Append `val` to a string list only if not already present — i.e. maintain a * set of distinct values. Used by COUNT(DISTINCT x) (#239). */
| 3735 | /* Append `val` to a string list only if not already present — i.e. maintain a |
| 3736 | * set of distinct values. Used by COUNT(DISTINCT x) (#239). */ |
| 3737 | static void distinct_list_add(char ***list, int *count, const char *val) { |
| 3738 | for (int i = 0; i < *count; i++) { |
| 3739 | if (strcmp((*list)[i], val) == 0) { |
| 3740 | return; |
| 3741 | } |
| 3742 | } |
| 3743 | int idx = (*count)++; |
| 3744 | *list = safe_realloc(*list, (size_t)(idx + SKIP_ONE) * sizeof(char *)); |
| 3745 | (*list)[idx] = heap_strdup(val); |
| 3746 | } |
| 3747 | |
| 3748 | /* Sort bindings by the ORDER BY key list (virtual variables) using bubble |
| 3749 | * sort; later keys break ties, direction is per key (#1334). */ |
no test coverage detected