Re: [PATCH 11/14] object-name: simplify computing common prefixes
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 20, 2026, 10:30 UTC
- Message-ID
- <ab0htJ0fafNdsXeR@pks.im>
- In-Reply-To
- <CAOLa=ZRU3=FqDo8SiJ=+qTsU79NEfoyAVp1uZYBX57SNPTZomw@mail.gmail.com>
On Fri, Mar 20, 2026 at 03:01:48AM -0700, Karthik Nayak wrote:
Show 22 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/hash.c b/hash.c
> > index 553f2008ea..e925b9754e 100644
> > --- a/hash.c
> > +++ b/hash.c
> > @@ -317,3 +317,21 @@ const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop)
> > /* Otherwise use the default one. */
> > return algop;
> > }
> > +
> > +unsigned oid_common_prefix_hexlen(const struct object_id *a,
> > + const struct object_id *b)
> > +{
> > + unsigned rawsz = hash_algos[a->algo].rawsz;
> > +
> > + for (unsigned i = 0; i < rawsz; i++) {
> > + if (a->hash[i] == b->hash[i])
> > + continue;
> > +
>
> Instead of transforming the bytes into 2 hex components we now compare
> the bytes themselves and perhaps then compare parts of it?Yes, exactly. It should be more performant overall compared to first converting to their respective hex presentations, even though I doubt it really matters in practice.
Show 10 quoted lines
> > + if ((a->hash[i] ^ b->hash[i]) & 0xf0) > > Okay so if the 4 MSB are the same then we end up here and return i * 2. > Makes sense. > > > + return i * 2; > > + else > > + return i * 2 + 1; > > If not, its the 4 LSB.
Yup.
Thanks!
Patrick