diff options
| author | shejialuo <shejialuo@gmail.com> | 2025-10-06 14:32:23 +0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-06 09:11:07 -0700 |
| commit | 03ef7762ea12f3b034a2281040bd61c74fd36386 (patch) | |
| tree | 8d16d26cba726ee89712b264bb25e024cba922c9 /string-list.c | |
| parent | 2462961280690837670d997bde64bd4ebf8ae66d (diff) | |
string-list: use bool instead of int for "exact_match"
The "exact_match" parameter in "get_entry_index" is used to indicate
whether a string is found or not, which is fundamentally a true/false
value. As we allow the use of bool, let's use bool instead of int to
make the function more semantically clear.
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
| -rw-r--r-- | string-list.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/string-list.c b/string-list.c index 343cf1ca90..d8da3dd414 100644 --- a/string-list.c +++ b/string-list.c @@ -16,7 +16,7 @@ void string_list_init_dup(struct string_list *list) /* if there is no exact match, point to the index where the entry could be * inserted */ static size_t get_entry_index(const struct string_list *list, const char *string, - int *exact_match) + bool *exact_match) { size_t left = 0, right = list->nr; compare_strings_fn cmp = list->cmp ? list->cmp : strcmp; @@ -29,18 +29,18 @@ static size_t get_entry_index(const struct string_list *list, const char *string else if (compare > 0) left = middle + 1; else { - *exact_match = 1; + *exact_match = true; return middle; } } - *exact_match = 0; + *exact_match = false; return right; } static size_t add_entry(struct string_list *list, const char *string) { - int exact_match = 0; + bool exact_match; size_t index = get_entry_index(list, string, &exact_match); if (exact_match) @@ -68,7 +68,7 @@ struct string_list_item *string_list_insert(struct string_list *list, const char void string_list_remove(struct string_list *list, const char *string, int free_util) { - int exact_match; + bool exact_match; int i = get_entry_index(list, string, &exact_match); if (exact_match) { @@ -82,9 +82,9 @@ void string_list_remove(struct string_list *list, const char *string, } } -int string_list_has_string(const struct string_list *list, const char *string) +bool string_list_has_string(const struct string_list *list, const char *string) { - int exact_match; + bool exact_match; get_entry_index(list, string, &exact_match); return exact_match; } @@ -92,7 +92,7 @@ int string_list_has_string(const struct string_list *list, const char *string) int string_list_find_insert_index(const struct string_list *list, const char *string, int negative_existing_index) { - int exact_match; + bool exact_match; int index = get_entry_index(list, string, &exact_match); if (exact_match) index = -1 - (negative_existing_index ? index : 0); @@ -101,7 +101,8 @@ int string_list_find_insert_index(const struct string_list *list, const char *st struct string_list_item *string_list_lookup(struct string_list *list, const char *string) { - int exact_match, i = get_entry_index(list, string, &exact_match); + bool exact_match; + size_t i = get_entry_index(list, string, &exact_match); if (!exact_match) return NULL; return list->items + i; |
