Thread (69 messages) 69 messages, 5 authors, 2017-05-04

Re: [PATCH v2 11/53] fast-import: convert to struct object_id

From: brian m. carlson <hidden>
Date: 2017-05-03 23:34:13

On Mon, May 01, 2017 at 06:27:58PM -0400, Jeff King wrote:
If you have 40 hex digits, then you have 20 hex pairs. But delimiting
them all takes only 19 slashes, since they only go in between pairs[1].

So the fully expanded formula is:

  GIT_MAX_HEXSZ +               (1) actual hex bytes
  (GIT_MAX_HEXSZ / 2) - 1 +     (2) internal slashes between pairs
  1                             (3) NUL terminator

which simplifies to 3/2 GIT_MAX_HEXSZ. It may be better to write it out
(the compiler can simplify) or explain that in the comment, though. It
took me a minute to figure out that it was correct, too.
I did simplify it like that, but I can improve the comment and the
computation, sure.  Clearly my comment wasn't good enough to avoid
confusion, so I appreciate the feedback.  I probably didn't think about
because I've touched the notes code recently, where the use of "19" made
it more obvious.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help