Re: [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Jan 23, 2021, 21:02 UTC
- Message-ID
- <d910be29-ba90-bbe1-fd96-523508b99781@gmail.com>
- In-Reply-To
- <CABPp-BEsoWs5ZEhS0KTHankzc8eUdmpn0uoF7t1ZtN8b2gwvBA@mail.gmail.com>
On 1/23/2021 3:24 PM, Elijah Newren wrote:
Show 19 quoted lines
> On Sat, Jan 23, 2021 at 11:58 AM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>> - for (i = 0; i < entries - 1; i++) {
>> + for (i = 0; i + 1 < istate->cache_nr; i++) {
>> /* path/file always comes after path because of the way
>> * the cache is sorted. Also path can appear only once,
>> * which means conflicting one would immediately follow.
>> */
>> - const struct cache_entry *this_ce = cache[i];
>> - const struct cache_entry *next_ce = cache[i + 1];
>> + const struct cache_entry *this_ce = istate->cache[i];
>> + const struct cache_entry *next_ce = istate->cache[i + 1];
>> const char *this_name = this_ce->name;
>> const char *next_name = next_ce->name;
>> int this_len = ce_namelen(this_ce);
> Makes sense. Thanks for explaining the i + 1 < istate->cache_nr bit
> in the commit message; made it easier to read through quickly. I'm
> curious if it deserves a comment in the code too, since it does feel
> slightly unusual.I would argue that "i + 1 < N" is a more natural way to write this, because we use "i + 1" as an index, so we want to ensure the index we are about to use is within range. "i < N - 1" is the backwards way to write that statement.
Thanks, -Stolee