From 3d1ff7193c52985ce4c2c64cb489a7bf15a3468b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 7 Apr 2009 11:08:19 -0700 Subject: [PATCH] cfg: Avoid doing unnecessary work in cfg_del_match(). It is only necessary to compact and terminate the array if we actually modified anything. --- lib/cfg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 -- 2.30.2