git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: David Kastrup <dak@gnu.org>
Cc: Miles Bader <miles@gnu.org>,
	Pierre Habouzit <madcoder@debian.org>,
	Timo Hirvonen <tihirvon@gmail.com>,
	git@vger.kernel.org, Junio C Hamano <junkio@cox.net>
Subject: Re: [PATCH] Make strbuf_cmp inline, constify its arguments and  optimize it a bit
Date: Sun, 7 Oct 2007 23:54:32 +0200	[thread overview]
Message-ID: <20071007215432.GC2765@steel.home> (raw)
In-Reply-To: <857ilylxhm.fsf@lola.goethe.zz>

David Kastrup, Sun, Oct 07, 2007 18:07:17 +0200:
> Miles Bader <miles@gnu.org> writes:
> 
> > Pierre Habouzit <madcoder@debian.org> writes:
> >>> 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.
> >
> > Couldn't you then just do:
> >
> >    int len = a->len < b->len ? a->len : b->len;
> >    int cmp = memcmp(a->buf, b->buf, len);
> >    if (cmp == 0)
> >       cmp = b->len - a->len;
> >    return cmp;
> >
> > [In the case where one string is a prefix of the other, then the longer
> > one is "greater".]
> >
> > ?
> 
> I fail to see where this variant is simpler than what we started the
> journey of simplification from.
> 
> The only change I consider worth checking from the whole series in
> this thread is making the function inline. 

It also makes arguments const (which admittedly wont make it faster).

> ... All the rest pretty much
> was worse than what we started from in that it needed to reevaluate
> more conditions and turned out more complicated and obfuscate even to
> the human reader.

it _is_ smaller. And it is _measurably_ faster on that thing I have at
home (and old p4).

  reply	other threads:[~2007-10-07 21:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-24  9:25 mini-refactor in rerere.c Pierre Habouzit
     [not found] ` <1190625904-22808-2-git-send-email-madcoder@debian.org>
     [not found]   ` <1190625904-22808-3-git-send-email-madcoder@debian.org>
2007-09-24 10:38     ` [PATCH 2/2] Make builtin-rerere use of strbuf nicer and more efficient Johannes Schindelin
2007-09-26  0:31     ` Junio C Hamano
2007-09-26  8:41       ` Pierre Habouzit
2007-10-07 14:00   ` [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit Alex Riesen
2007-10-07 14:24     ` Timo Hirvonen
2007-10-07 14:39       ` Pierre Habouzit
2007-10-07 15:46         ` Miles Bader
2007-10-07 16:07           ` David Kastrup
2007-10-07 21:54             ` Alex Riesen [this message]
2007-10-07 22:12               ` Wincent Colaiuta
2007-10-07 22:31                 ` Alex Riesen
2007-10-08  1:45                   ` Miles Bader
2007-10-08  7:23                     ` Pierre Habouzit
2007-10-08  8:54                       ` Florian Weimer
2007-10-08 18:51                         ` Alex Riesen
2007-10-07 16:11         ` Johannes Schindelin
2007-10-07 16:18           ` Timo Hirvonen
2007-10-07 18:25             ` Johannes Schindelin
2007-10-07 16:54           ` Pierre Habouzit
2007-10-07 14:24     ` David Kastrup
2007-10-07 16:10       ` Alex Riesen
2007-10-07 16:27         ` David Kastrup
2007-10-07 21:57           ` Alex Riesen
2007-10-08  2:19             ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071007215432.GC2765@steel.home \
    --to=raa.lkml@gmail.com \
    --cc=dak@gnu.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=madcoder@debian.org \
    --cc=miles@gnu.org \
    --cc=tihirvon@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).