From: Patrick Steinhardt Date: Fri, 20 Mar 2026 10:30:12 GMT Subject: Re: [PATCH 11/14] object-name: simplify computing common prefixes Message-ID: In-Reply-To: On Fri, Mar 20, 2026 at 03:01:48AM -0700, Karthik Nayak wrote: > Patrick Steinhardt 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. > > + 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