From 91932471c9b66d57d74a564feadc7e8816d8fd86 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:49:40 +0100 Subject: [PATCH] Refactor count_distinct_keys_info Adding a call to get_key_placeholder_by_index outside of the loop makes the code a lot more readable, and the extra call is not expensive enough to worry. --- src/handler/lib/policy.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/handler/lib/policy.c b/src/handler/lib/policy.c index 12aabb98b..315e133ab 100644 --- a/src/handler/lib/policy.c +++ b/src/handler/lib/policy.c @@ -1723,13 +1723,16 @@ int get_key_placeholder_by_index(const policy_node_t *policy, } int count_distinct_keys_info(const policy_node_t *policy) { - policy_node_key_placeholder_t placeholder; - int ret = -1, cur, n_placeholders; + int ret = -1, cur; - for (cur = 0; - cur < (n_placeholders = get_key_placeholder_by_index(policy, cur, NULL, &placeholder)); - ++cur) { - if (n_placeholders < 0) { + int n_placeholders = get_key_placeholder_by_index(policy, 0, NULL, NULL); + if (n_placeholders < 0) { + return -1; + } + + for (cur = 0; cur < n_placeholders; ++cur) { + policy_node_key_placeholder_t placeholder; + if (0 > get_key_placeholder_by_index(policy, cur, NULL, &placeholder) { return -1; } ret = MAX(ret, placeholder.key_index + 1);