From: Ben Pfaff Date: Tue, 7 Apr 2009 18:08:19 +0000 (-0700) Subject: cfg: Avoid doing unnecessary work in cfg_del_match(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d1ff7193c52985ce4c2c64cb489a7bf15a3468b;p=openvswitch cfg: Avoid doing unnecessary work in cfg_del_match(). It is only necessary to compact and terminate the array if we actually modified anything. --- diff --git a/lib/cfg.c b/lib/cfg.c index 8d9a4d09..d588e642 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -545,6 +545,7 @@ cfg_del_section(const char *section_, ...) void cfg_del_match(const char *pattern_, ...) { + bool matched = false; char *pattern; char **p; @@ -554,13 +555,16 @@ cfg_del_match(const char *pattern_, ...) if (!fnmatch(pattern, *p, 0)) { free(*p); *p = NULL; + matched = true; } } - svec_compact(&cfg); - svec_terminate(&cfg); + if (matched) { + svec_compact(&cfg); + svec_terminate(&cfg); + dirty = true; + } free(pattern); - dirty = true; } /* Fills 'svec' with all of the key-value pairs that have sections that