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>
René Scharfe committed
Jul 21, 2016 at 18:46 UTC
31471ba21ee29886ab856981e52f723c913d7f40
2 files changed
+8
-5
strbuf.c
+7
@@ -197,6 +197,13 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len)
197
strbuf_setlen(sb, sb->len + len);
198
}
199
200
+void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
201
+{
202
+ strbuf_grow(sb, sb2->len);
203
+ memcpy(sb->buf + sb->len, sb2->buf, sb2->len);
204
+ strbuf_setlen(sb, sb->len + sb2->len);
205
+}
206
+
207
void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
208
{
209
strbuf_grow(sb, len);
strbuf.h
+1
-5
@@ -263,11 +263,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
263
/**
264
* Copy the contents of another buffer at the end of the current one.
265
*/
266
-static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
267
-{
268
- strbuf_grow(sb, sb2->len);
269
- strbuf_add(sb, sb2->buf, sb2->len);
270
-}
266
+extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
267
268
/**
269
* Copy part of the buffer from a given position till a given length to the