All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <junkio@cox.net>, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit
Date: Sun, 7 Oct 2007 16:00:52 +0200	[thread overview]
Message-ID: <20071007140052.GA3260@steel.home> (raw)
In-Reply-To: <1190625904-22808-2-git-send-email-madcoder@debian.org>

It is definitely less code (also object code). It is not always
measurably faster (but mostly is).

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 strbuf.c |   12 ------------
 strbuf.h |    9 ++++++++-
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/strbuf.c b/strbuf.c
index f4201e1..215837b 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -58,18 +58,6 @@ void strbuf_rtrim(struct strbuf *sb)
 	sb->buf[sb->len] = '\0';
 }
 
-int strbuf_cmp(struct strbuf *a, struct strbuf *b)
-{
-	int cmp;
-	if (a->len < b->len) {
-		cmp = memcmp(a->buf, b->buf, a->len);
-		return cmp ? cmp : -1;
-	} else {
-		cmp = memcmp(a->buf, b->buf, b->len);
-		return cmp ? cmp : a->len != b->len;
-	}
-}
-
 void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
 				   const void *data, size_t dlen)
 {
diff --git a/strbuf.h b/strbuf.h
index 9b9e861..3116387 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -78,7 +78,14 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
 
 /*----- content related -----*/
 extern void strbuf_rtrim(struct strbuf *);
-extern int strbuf_cmp(struct strbuf *, struct strbuf *);
+static inline int strbuf_cmp(const struct strbuf *a, const 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;
+}
 
 /*----- add data in your buffer -----*/
 static inline void strbuf_addch(struct strbuf *sb, int c) {
-- 
1.5.3.4.223.g78587

  parent reply	other threads:[~2007-10-07 14:01 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   ` Alex Riesen [this message]
2007-10-07 14:24     ` [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit 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
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=20071007140052.GA3260@steel.home \
    --to=raa.lkml@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=madcoder@debian.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.