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

Re: Tabs in commit messages - de-tabify option in strbuf_stripspace()?

From
Jeff King <peff@peff.net>
Date
Mar 16, 2016, 05:17 UTC
Message-ID
<20160316051748.GA3524@sigill.intra.peff.net>
In-Reply-To
<CA+55aFyFHmmoHMgRkuBqNUho=tiJ=VwxHWzcGw3pRjr+aGS7ZQ@mail.gmail.com>
On Tue, Mar 15, 2016 at 09:57:16PM -0700, Linus Torvalds wrote:
Show 18 quoted lines
> On Tue, Mar 15, 2016 at 9:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > It also ignores that byte counts of non-HT bytes may not necessarily
> > match display columns.  There is utf8_width() function exported from
> > utf8.c for that purpose.
> 
> Hmm. I did that to now make it horribly slower. Doing the
> per-character widths really does horrible things for performance.
> 
> That said, I think I can make it do the fast thing for lines that have
> no tabs at all, which is the big bulk of it. So it would do the width
> calculations only in the rare "yes, I found a tab" case.
> 
> I already wrote it in a way that non-tab lines end up just looping
> over the line looking for a tab and then fall back to the old code.
> 
> I might just have to make that behavior a bit more explicit. Let me
> stare at it a bit, but it won't happen until tomorrow, I think.

I wondered about performance when reading yours, and measured a straight "git log >/dev/null" on the kernel at about 3% slower (best-of-five and average). We can get most of that back by sticking a

    memchr(line, '\t', linelen);

in front and skipping the loop if it returns NULL. You can also implement your loop in terms of memchr() calls to skip to the next tab, but I don't know if it's worth it. It's really only worth spending time optimizing the non-tab case (and even then, only worth it for trivial things like "use the already optimized-as-hell memchr").

-Peff
Previous: Linus Torvalds
Message 17 of 17 in “Tabs in commit messages - de-tabify option in strbuf_stripspace()?”
  1. Linus TorvaldsMar 16, 2016
  2. Stefan BellerMar 16, 2016
  3. Linus TorvaldsMar 16, 2016
  4. Randall S. BeckerMar 16, 2016
  5. Junio C HamanoMar 16, 2016
  6. Linus TorvaldsMar 16, 2016
  7. Stefan BellerMar 16, 2016
  8. Stefan BellerMar 16, 2016
  9. Marc BranchaudMar 16, 2016
  10. Duy NguyenMar 16, 2016
  11. Linus TorvaldsMar 16, 2016
  12. Junio C HamanoMar 16, 2016
  13. Matthieu MoyMar 20, 2016
  14. Linus TorvaldsMar 16, 2016
  15. Junio C HamanoMar 16, 2016
  16. Linus TorvaldsMar 16, 2016
  17. Jeff KingMar 16, 2016

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.