]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Improved performance of previous duplicate key parsing change.
authorTimo Sirainen <tss@iki.fi>
Mon, 15 Nov 2010 16:49:26 +0000 (16:49 +0000)
committerTimo Sirainen <tss@iki.fi>
Mon, 15 Nov 2010 16:49:26 +0000 (16:49 +0000)
src/lib-settings/settings-parser.c

index ea03f5edb7deb2926a0f0144d5ec80a766c2ac5c..0b21d972b45c092ee086f8c259933d89a5079d78 100644 (file)
@@ -652,7 +652,7 @@ settings_parse(struct setting_parser_context *ctx, struct setting_link *link,
 
 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 @@ settings_find_key_nth(struct setting_parser_context *ctx, const char *key,
        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 @@ settings_find_key(struct setting_parser_context *ctx, const char *key,
                  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 @@ static int settings_parse_keyvalue(struct setting_parser_context *ctx,
        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 @@ static int settings_parse_keyvalue(struct setting_parser_context *ctx,
                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;
 }