Skip to content

Commit

Permalink
Microoptimize strbuf_cmp
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alex Riesen authored and Junio C Hamano committed Mar 20, 2009
1 parent e392a85 commit 8f02465
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8f02465

Please sign in to comment.