From: Pierre Habouzit <madcoder@debian.org>
To: Miles Bader <miles@gnu.org>
Cc: Alex Riesen <raa.lkml@gmail.com>,
Wincent Colaiuta <win@wincent.com>, David Kastrup <dak@gnu.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: Mon, 08 Oct 2007 09:23:12 +0200 [thread overview]
Message-ID: <20071008072312.GA22552@artemis.corp> (raw)
In-Reply-To: <87odfapefc.fsf@catnip.gol.com>
[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]
On Mon, Oct 08, 2007 at 01:45:27AM +0000, Miles Bader wrote:
> Alex Riesen <raa.lkml@gmail.com> writes:
> > int strbuf_cmp2(struct strbuf *a, struct strbuf *b)
> > {
> > int len = a->len < b->len ? a->len: b->len;
> > int cmp = memcmp(a->buf, b->buf, len);
> > if (cmp)
> > return cmp;
> > return a->len < b->len ? -1: a->len != b->len;
> > }
>
> BTW, why are you making such effort to return only -1, 0, or 1 in the
> last line? memcmp/strcmp make no such guarantee; e.g. glibc says:
>
> The `strcmp' function compares the string S1 against S2, returning
> a value that has the same sign as the difference between the first
> differing pair of characters (interpreted as `unsigned char'
> objects, then promoted to `int').
>
> If the two strings are equal, `strcmp' returns `0'.
>
> A consequence of the ordering used by `strcmp' is that if S1 is an
> initial substring of S2, then S1 is considered to be "less than"
> S2.
>
> So I think the last line can just be:
>
> return a->len - b->len;
Won't work because ->len are size_t and return value is int, so on 64
bits platform, this has chances to overflow.
FWIW I believe we are doing micro-benchs in a function that is used in
2 places in git right now.
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-10-08 7:23 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
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 [this message]
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=20071008072312.GA22552@artemis.corp \
--to=madcoder@debian.org \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=miles@gnu.org \
--cc=raa.lkml@gmail.com \
--cc=tihirvon@gmail.com \
--cc=win@wincent.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).