diff options
| author | shejialuo <shejialuo@gmail.com> | 2025-10-06 14:32:31 +0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-06 09:11:07 -0700 |
| commit | e8a32e766fe3f5e40fb8918a4d825e6d0b9aa272 (patch) | |
| tree | e17efa382065921b2ff1d4559f72a69a4a842b5f /range-diff.h | |
| parent | 03ef7762ea12f3b034a2281040bd61c74fd36386 (diff) | |
string-list: replace negative index encoding with "exact_match" parameter
The "string_list_find_insert_index()" function is used to determine
the correct insertion index for a new string within the string list.
The function also doubles up to convey if the string is already
existing in the list, this is done by returning a negative index
"-1 -index". Users are expected to decode this information. This
approach has several limitations:
1. It requires the callers to look into the detail of the function to
understand how to decode the negative index encoding.
2. Using int for indices can cause overflow issues when dealing with
large string lists.
To address these limitations, change the function to return size_t for
the index value and use a separate bool parameter to indicate whether
the index refers to an existing entry or an insertion point.
In some cases, the callers of "string_list_find_insert_index" only need
the index position and don't care whether an exact match is found.
However, "get_entry_index" currently requires a non-NULL "exact_match"
parameter, forcing these callers to declare unnecessary variables.
Let's allow callers to pass NULL for the "exact_match" parameter when
they don't need this information, reducing unnecessary variable
declarations in calling code.
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.h')
0 files changed, 0 insertions, 0 deletions
