]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Optimize getting values without %variables
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Dec 2024 09:02:18 +0000 (11:02 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:01 +0000 (10:40 +0200)
src/lib-settings/settings.c

index 6f074815a70aedc501ab6e394b168d2157c6489f..4100d40489203ccd2a4d92177daa2b7fc7033190 100644 (file)
@@ -549,6 +549,7 @@ settings_var_expand(struct settings_apply_ctx *ctx, unsigned int key_idx,
 {
        struct settings_file file;
        const char *orig_value = *value;
+       bool changed;
 
        if ((ctx->flags & SETTINGS_GET_FLAG_NO_EXPAND) != 0)
                return 0;
@@ -557,17 +558,23 @@ settings_var_expand(struct settings_apply_ctx *ctx, unsigned int key_idx,
            ctx->info->defines[key_idx].type == SET_FILTER_ARRAY)
                return 0;
 
-       str_truncate(ctx->str, 0);
        if (ctx->info->defines[key_idx].type == SET_FILE) {
                settings_file_get(*value, &ctx->mpool->pool, &file);
                /* Make sure only the file path is var-expanded. */
                *value = file.path;
        }
-       if (var_expand(ctx->str, *value, &ctx->var_params, error_r) < 0 &&
-           (ctx->flags & SETTINGS_GET_FLAG_FAKE_EXPAND) == 0)
-               return -1;
+       if (strchr(*value, '%') == NULL) {
+               /* fast path: No %variables in the value */
+               changed = FALSE;
+       } else {
+               str_truncate(ctx->str, 0);
+               if (var_expand(ctx->str, *value, &ctx->var_params, error_r) < 0 &&
+                   (ctx->flags & SETTINGS_GET_FLAG_FAKE_EXPAND) == 0)
+                       return -1;
+               changed = strcmp(*value, str_c(ctx->str)) != 0;
+       }
 
-       if (strcmp(*value, str_c(ctx->str)) == 0) {
+       if (!changed) {
                /* unchanged value */
                if (ctx->info->defines[key_idx].type == SET_FILE) {
                        /* Restore full SET_FILE value */