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>
Alex Riesen committed
Mar 19, 2009 at 23:27 UTC
8f0246551c3964eeb16d9c9f39845bd53af8bda8
1 file changed
+5
-8
strbuf.c
+5
-8
@@ -139,14 +139,11 @@ void strbuf_list_free(struct strbuf **sbs)
139
140
int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
141
{
142
- int cmp;
143
- if (a->len < b->len) {
144
- cmp = memcmp(a->buf, b->buf, a->len);
145
- return cmp ? cmp : -1;
146
- } else {
147
- cmp = memcmp(a->buf, b->buf, b->len);
148
- return cmp ? cmp : a->len != b->len;
149
- }
142
+ int len = a->len < b->len ? a->len: b->len;
143
+ int cmp = memcmp(a->buf, b->buf, len);
144
+ if (cmp)
145
+ return cmp;
146
+ return a->len < b->len ? -1: a->len != b->len;
147
}
148
149
void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,