Git fork

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>

authored by

shejialuo and committed by
Junio C Hamano
03ef7762 24629612

+11 -10
+10 -9
string-list.c
··· 16 16 /* if there is no exact match, point to the index where the entry could be 17 17 * inserted */ 18 18 static size_t get_entry_index(const struct string_list *list, const char *string, 19 - int *exact_match) 19 + bool *exact_match) 20 20 { 21 21 size_t left = 0, right = list->nr; 22 22 compare_strings_fn cmp = list->cmp ? list->cmp : strcmp; ··· 29 29 else if (compare > 0) 30 30 left = middle + 1; 31 31 else { 32 - *exact_match = 1; 32 + *exact_match = true; 33 33 return middle; 34 34 } 35 35 } 36 36 37 - *exact_match = 0; 37 + *exact_match = false; 38 38 return right; 39 39 } 40 40 41 41 static size_t add_entry(struct string_list *list, const char *string) 42 42 { 43 - int exact_match = 0; 43 + bool exact_match; 44 44 size_t index = get_entry_index(list, string, &exact_match); 45 45 46 46 if (exact_match) ··· 68 68 void string_list_remove(struct string_list *list, const char *string, 69 69 int free_util) 70 70 { 71 - int exact_match; 71 + bool exact_match; 72 72 int i = get_entry_index(list, string, &exact_match); 73 73 74 74 if (exact_match) { ··· 82 82 } 83 83 } 84 84 85 - int string_list_has_string(const struct string_list *list, const char *string) 85 + bool string_list_has_string(const struct string_list *list, const char *string) 86 86 { 87 - int exact_match; 87 + bool exact_match; 88 88 get_entry_index(list, string, &exact_match); 89 89 return exact_match; 90 90 } ··· 92 92 int string_list_find_insert_index(const struct string_list *list, const char *string, 93 93 int negative_existing_index) 94 94 { 95 - int exact_match; 95 + bool exact_match; 96 96 int index = get_entry_index(list, string, &exact_match); 97 97 if (exact_match) 98 98 index = -1 - (negative_existing_index ? index : 0); ··· 101 101 102 102 struct string_list_item *string_list_lookup(struct string_list *list, const char *string) 103 103 { 104 - int exact_match, i = get_entry_index(list, string, &exact_match); 104 + bool exact_match; 105 + size_t i = get_entry_index(list, string, &exact_match); 105 106 if (!exact_match) 106 107 return NULL; 107 108 return list->items + i;
+1 -1
string-list.h
··· 172 172 /* Use these functions only on sorted lists: */ 173 173 174 174 /** Determine if the string_list has a given string or not. */ 175 - int string_list_has_string(const struct string_list *list, const char *string); 175 + bool string_list_has_string(const struct string_list *list, const char *string); 176 176 int string_list_find_insert_index(const struct string_list *list, const char *string, 177 177 int negative_existing_index); 178 178