git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sha1_file: add slash once in for_each_file_in_obj_subdir()

From
René Scharfe <l.s.r@web.de>
Date
Jul 9, 2017, 13:26 UTC
Message-ID
<f83adfa6-89f9-9c0e-bd69-eca56d3fcf25@web.de>
In-Reply-To
<20170709110016.nusy62u2morqvwmm@sigill.intra.peff.net>
Am 09.07.2017 um 13:00 schrieb Jeff King:
Show 20 quoted lines
> On Sat, Jul 08, 2017 at 10:59:06AM +0200, René Scharfe wrote:
> 
>> Add the slash between loose object subdirectory and file name just once
>> outside the loop instead of overwriting it with each readdir call.
>> Redefine baselen as the length with that slash, and add dirlen for the
>> length without it.  The result is slightly less wasteful and can use the
>> the cheaper strbuf_addstr instead of strbuf_addf without losing clarity.
> 
> This patch looks correct to me.
> 
> I'm a little lukewarm on it overall, though. I'd be shocked if the
> efficiency change is measurable. What I really care about is whether the
> result is easier to read or not.
> 
> On the plus side, this moves an invariant out of the loop. On the minus
> side, it has to introduce an extra variable for "length we add on to"
> versus "dir length to pass to the subdir_cb". That's not rocket science,
> but it does slightly complicate things (though I note we already have
> "origlen", so this is bumping us from 2 to 3 length variables, not 1 to
> 2).

Admittedly this is more of an OCD thing. Overwriting a character 200 times or parsing a format string don't very long compared to the rest of the function, but it's a bit itchy.

René
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 7 in “sha1_file: add slash once in for_each_file_in_obj_subdir()”
  1. sha1_file: add slash once in for_each_file_in_obj_subdir()René Scharfe, Jul 8, 2017
  2. Jeff KingJul 9, 2017
  3. René ScharfeJul 9, 2017
  4. Junio C HamanoJul 9, 2017
  5. Jeff KingJul 10, 2017
  6. Junio C HamanoJul 10, 2017
  7. René ScharfeJul 12, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.