summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Riesen <raa.lkml@gmail.com>2009-03-19 23:27:32 +0100
committerJunio C Hamano <gitster@pobox.com>2009-03-20 09:35:32 -0700
commit8f0246551c3964eeb16d9c9f39845bd53af8bda8 (patch)
tree49db2be5a4791408e84656ddaedc7e20c20110e3
parente392a852364e375e916c1dd4f87a7584b348410a (diff)
downloadgit-8f0246551c3964eeb16d9c9f39845bd53af8bda8.tar.gz
Microoptimize strbuf_cmp
It can be less object code and may be even faster, even if at the moment there is no callers to take an advantage of that. This implementation can be trivially made inlinable later. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--strbuf.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/strbuf.c b/strbuf.c
index 6ed06840b8..bfbd81632e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -139,14 +139,11 @@ void strbuf_list_free(struct strbuf **sbs)
int strbuf_cmp(const struct strbuf *a, const 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;
- }
+ 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;
}
void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,