Skip to content

Commit

Permalink
Refactor count_distinct_keys_info
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bigspider committed Feb 26, 2024
1 parent 205a65a commit 9193247
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/handler/lib/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9193247

Please sign in to comment.