Re: [PATCH v2] last-modified: implement faster algorithm
- From
Toon Claes <toon@iotcl.com>
- Date
- Oct 23, 2025, 08:01 UTC
- Message-ID
- <87347aqc65.fsf@iotcl.com>
- In-Reply-To
- <xmqqy0p4uoqc.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 19 quoted lines
> Toon Claes <toon@iotcl.com> writes:
>
>> +static size_t path_idx(struct last_modified *lm, char *path)
>> +{
>> + struct last_modified_entry *ent;
>> + ent = hashmap_get_entry_from_hash(&lm->paths, strhash(path), path,
>> + struct last_modified_entry, hashent);
>> +
>> + return ent ? ent->diff_idx : -1;
>> +}
>
> size_t is unsigned and cannot reutrn -1 sanely, unless the caller
> knows that ((size_t)-1) signals an error. The compiler warns, and
> we compile with -Werror, so we end up getting
>
> builtin/last-modified.c: In function 'path_idx':
> builtin/last-modified.c:235:38: error: operand of '?:' changes signedness from 'int' to 'size_t' {aka 'long unsigned int'} due to unsignedness of other operand [-Werror=sign-compare]
> 235 | return ent ? ent->diff_idx : -1;
> | ^~Whoops, I didn't realize I wasn't compiling with the proper DEVELOPER settings. I recently set up a new computer and didn't bring over all configuration correctly.
I just sent out v3 and in that version I decided to solve this issue differently: inline the code from path_idx() in only place it was used.
-- Cheers, Toon