dovecot-2.0: lib-settings: Improved performance of previous dupl...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 15 18:49:29 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/172942ae0b58
changeset: 12424:172942ae0b58
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 15 16:49:26 2010 +0000
description:
lib-settings: Improved performance of previous duplicate key parsing change.

diffstat:

 src/lib-settings/settings-parser.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (63 lines):

diff -r 656da7e0d6b9 -r 172942ae0b58 src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Mon Nov 15 16:42:19 2010 +0000
+++ b/src/lib-settings/settings-parser.c	Mon Nov 15 16:49:26 2010 +0000
@@ -652,7 +652,7 @@
 
 static bool
 settings_find_key_nth(struct setting_parser_context *ctx, const char *key,
-		      unsigned int n, const struct setting_define **def_r,
+		      unsigned int *n, const struct setting_define **def_r,
 		      struct setting_link **link_r)
 {
 	const struct setting_define *def;
@@ -661,16 +661,18 @@
 	unsigned int i;
 
 	/* try to find from roots */
-	for (i = 0; i < ctx->root_count; i++) {
+	for (i = *n; i < ctx->root_count; i++) {
 		def = setting_define_find(ctx->roots[i].info, key);
-		if (def != NULL && n-- == 0) {
+		if (def != NULL) {
+			*n = i + 1;
 			*def_r = def;
 			*link_r = &ctx->roots[i];
 			return TRUE;
 		}
 	}
-	if (n > 0)
+	if (*n > ctx->root_count)
 		return FALSE;
+	*n += 1;
 
 	/* try to find from links */
 	end = strrchr(key, SETTINGS_SEPARATOR);
@@ -696,7 +698,9 @@
 		  const struct setting_define **def_r,
 		  struct setting_link **link_r)
 {
-	return settings_find_key_nth(ctx, key, 0, def_r, link_r);
+	unsigned int n = 0;
+
+	return settings_find_key_nth(ctx, key, &n, def_r, link_r);
 }
 
 static void
@@ -732,7 +736,7 @@
 	struct setting_link *link;
 	unsigned int n = 0;
 
-	if (!settings_find_key(ctx, key, &def, &link)) {
+	if (!settings_find_key_nth(ctx, key, &n, &def, &link)) {
 		ctx->error = p_strconcat(ctx->parser_pool,
 					 "Unknown setting: ", key, NULL);
 		return 0;
@@ -747,7 +751,7 @@
 		if (settings_parse(ctx, link, def, key, value) < 0)
 			return -1;
 		/* there may be more instances of the setting */
-	} while (settings_find_key_nth(ctx, key, ++n, &def, &link));
+	} while (settings_find_key_nth(ctx, key, &n, &def, &link));
 	return 1;
 }
 


More information about the dovecot-cvs mailing list