From a64d898b03401076019b1b206969b99d71467205 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 20 Dec 2024 11:02:18 +0200 Subject: [PATCH] lib-settings: Optimize getting values without %variables --- src/lib-settings/settings.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index 6f074815a7..4100d40489 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -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 */ -- 2.47.3