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

Re: [PATCH] general style: replaces memcmp() with starts_with()

From
Jeff King <peff@peff.net>
Date
Mar 12, 2014, 18:00 UTC
Message-ID
<20140312180026.GB7982@sigill.intra.peff.net>
In-Reply-To
<532097D0.4070909@web.de>
On Wed, Mar 12, 2014 at 06:22:24PM +0100, Jens Lehmann wrote:
Show 7 quoted lines
> > Let me know if you still think the hunk should be dropped there.
> 
> Yes, I think so. That spot uses memcmp() because ce->name may
> not be 0-terminated. If that assumption isn't correct, it should
> be replaced with a plain strcmp() instead (while also dropping
> the ce_namelen() comparison in the line above). But starts_with()
> points into the wrong direction there.

I think the length-check and memcmp is an optimization[1] here. But we should be able to encapsulate that pattern and avoid magic numbers entirely with something like mem_equals(). See my other response for more details.

-Peff
[1] Getting rid of the magic number entirely means we have to call
    strlen(".gitmodules"), which seems like it is working against this
    optimization. But I think past experiments have shown that decent
    compilers will optimize strlen on a string literal to a constant, so
    as long as mem_equals is an inline, it should be equivalent.
Previous: Jens LehmannNext: Duy Nguyen
Message 9 of 10 in “general style: replaces memcmp() with starts_with()”
  1. general style: replaces memcmp() with starts_with()Quint Guvernator, Mar 12, 2014
  2. Duy NguyenMar 12, 2014
  3. Quint GuvernatorMar 12, 2014
  4. Michael HaggertyMar 13, 2014
  5. Quint GuvernatorMar 14, 2014
  6. Jens LehmannMar 12, 2014
  7. Quint GuvernatorMar 12, 2014
  8. Jens LehmannMar 12, 2014
  9. Jeff KingMar 12, 2014
  10. Duy NguyenMar 12, 2014

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.