if there is no exact match, point to the index where the entry could be * inserted */
| 16 | /* if there is no exact match, point to the index where the entry could be |
| 17 | * inserted */ |
| 18 | static size_t get_entry_index(const struct string_list *list, const char *string, |
| 19 | bool *exact_match) |
| 20 | { |
| 21 | size_t left = 0, right = list->nr; |
| 22 | compare_strings_fn cmp = list->cmp ? list->cmp : strcmp; |
| 23 | |
| 24 | while (left < right) { |
| 25 | size_t middle = left + (right - left) / 2; |
| 26 | int compare = cmp(string, list->items[middle].string); |
| 27 | if (compare < 0) |
| 28 | right = middle; |
| 29 | else if (compare > 0) |
| 30 | left = middle + 1; |
| 31 | else { |
| 32 | if (exact_match) |
| 33 | *exact_match = true; |
| 34 | return middle; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (exact_match) |
| 39 | *exact_match = false; |
| 40 | return right; |
| 41 | } |
| 42 | |
| 43 | static size_t add_entry(struct string_list *list, const char *string) |
| 44 | { |
no test coverage detected