aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-07-21 18:46:44 +0200
committerJunio C Hamano <gitster@pobox.com>2016-07-22 09:22:26 -0700
commit31471ba21ee29886ab856981e52f723c913d7f40 (patch)
tree3d816df586a76c6112c81fe276c956248e9852c5
parent8109984d619467ad26c6a76d59b0a5de8a86e6d6 (diff)
downloadgit-31471ba21ee29886ab856981e52f723c913d7f40.tar.gz
git-31471ba21ee29886ab856981e52f723c913d7f40.tar.xz
strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf()
Implement strbuf_addbuf() as a normal function in order to avoid calling strbuf_grow() twice, with the second callinside strbud_add() being a no-op. This is slightly faster and also reduces the text size a bit. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--strbuf.c7
-rw-r--r--strbuf.h6
2 files changed, 8 insertions, 5 deletions
diff --git a/strbuf.c b/strbuf.c
index 958387562..600e27ea4 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -197,6 +197,13 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len)
strbuf_setlen(sb, sb->len + len);
}
+void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
+{
+ strbuf_grow(sb, sb2->len);
+ memcpy(sb->buf + sb->len, sb2->buf, sb2->len);
+ strbuf_setlen(sb, sb->len + sb2->len);
+}
+
void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
{
strbuf_grow(sb, len);
diff --git a/strbuf.h b/strbuf.h
index 5397d91d7..45d25d7c4 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -263,11 +263,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
/**
* Copy the contents of another buffer at the end of the current one.
*/
-static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
-{
- strbuf_grow(sb, sb2->len);
- strbuf_add(sb, sb2->buf, sb2->len);
-}
+extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
/**
* Copy part of the buffer from a given position till a given length to the