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>
This commit is contained in:
parent
e392a85236
commit
8f0246551c
13
strbuf.c
13
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 strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
|
||||||
{
|
{
|
||||||
int cmp;
|
int len = a->len < b->len ? a->len: b->len;
|
||||||
if (a->len < b->len) {
|
int cmp = memcmp(a->buf, b->buf, len);
|
||||||
cmp = memcmp(a->buf, b->buf, a->len);
|
if (cmp)
|
||||||
return cmp ? cmp : -1;
|
return cmp;
|
||||||
} else {
|
return a->len < b->len ? -1: a->len != b->len;
|
||||||
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,
|
void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
|
||||||
|
Loading…
Reference in New Issue
Block a user