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

Re: [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit

From
Pierre Habouzit <madcoder@debian.org>
Date
Oct 7, 2007, 16:54 UTC
Message-ID
<20071007165424.GF10024@artemis.corp>
In-Reply-To
<Pine.LNX.4.64.0710071710190.4174@racer.site>
On Sun, Oct 07, 2007 at 04:11:29PM +0000, Johannes Schindelin wrote:
Show 19 quoted lines
> Hi,
> 
> On Sun, 7 Oct 2007, Pierre Habouzit wrote:
> 
> > On Sun, Oct 07, 2007 at 02:24:25PM +0000, Timo Hirvonen wrote:
> >
> > > strbuf->buf is always non-NULL and NUL-terminated so you could just do
> > > 
> > > static inline int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
> > > {
> > > 	int len = a->len < b->len ? a->len : b->len;
> > > 	return memcmp(a->buf, b->buf, len + 1);
> > > }
> > 
> >   doesn't work, because a buffer can have (in some very specific cases)
> > an embeded NUL.
> 
> But it should work.  The function memcmp() could not care less if there is 
> a NUL or not, it just compares until it finds a difference.
  not if your one of your strbuf has as prefix, the other followed by
'\0', then anything else (including nothing ;p).
  Your test would yield equality.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Previous: Johannes SchindelinNext: David Kastrup
Message 20 of 25 in “mini-refactor in rerere.c”
  1. Pierre HabouzitSep 24, 2007
  2. Johannes SchindelinSep 24, 2007
  3. Junio C HamanoSep 26, 2007
  4. Pierre HabouzitSep 26, 2007
  5. Make strbuf_cmp inline, constify its arguments and optimize it a bitAlex Riesen, Oct 7, 2007
  6. Timo HirvonenOct 7, 2007
  7. Pierre HabouzitOct 7, 2007
  8. Miles BaderOct 7, 2007
  9. David KastrupOct 7, 2007
  10. Alex RiesenOct 7, 2007
  11. Wincent ColaiutaOct 7, 2007
  12. Alex RiesenOct 7, 2007
  13. Miles BaderOct 8, 2007
  14. Pierre HabouzitOct 8, 2007
  15. Florian WeimerOct 8, 2007
  16. Alex RiesenOct 8, 2007
  17. Johannes SchindelinOct 7, 2007
  18. Timo HirvonenOct 7, 2007
  19. Johannes SchindelinOct 7, 2007
  20. Pierre HabouzitOct 7, 2007
  21. David KastrupOct 7, 2007
  22. Alex RiesenOct 7, 2007
  23. David KastrupOct 7, 2007
  24. Alex RiesenOct 7, 2007
  25. Jeff KingOct 8, 2007

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.