From 8109984d619467ad26c6a76d59b0a5de8a86e6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 19 Jul 2016 20:36:29 +0200 Subject: use strbuf_addbuf() for appending a strbuf to another Use strbuf_addbuf() where possible; it's shorter and more efficient. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano diff --git a/dir.c b/dir.c index 88e8958..05b9884 100644 --- a/dir.c +++ b/dir.c @@ -2346,7 +2346,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra varint_len = encode_varint(untracked->ident.len, varbuf); strbuf_add(out, varbuf, varint_len); - strbuf_add(out, untracked->ident.buf, untracked->ident.len); + strbuf_addbuf(out, &untracked->ident); strbuf_add(out, ouc, ouc_size(len)); free(ouc); diff --git a/path.c b/path.c index 38f2ebd..e1bc8f0 100644 --- a/path.c +++ b/path.c @@ -246,7 +246,7 @@ static void do_submodule_path(struct strbuf *buf, const char *path, strbuf_addstr(buf, git_dir); } strbuf_addch(buf, '/'); - strbuf_addstr(&git_submodule_dir, buf->buf); + strbuf_addbuf(&git_submodule_dir, buf); strbuf_vaddf(buf, fmt, args); diff --git a/wt-status.c b/wt-status.c index ced53dd..51c0d7f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1060,7 +1060,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) strbuf_addf(split[1], "%s ", abbrev); strbuf_reset(line); for (i = 0; split[i]; i++) - strbuf_addf(line, "%s", split[i]->buf); + strbuf_addbuf(line, split[i]); } } for (i = 0; split[i]; i++) -- cgit v0.10.2-6-g49f6 From 31471ba21ee29886ab856981e52f723c913d7f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 21 Jul 2016 18:46:44 +0200 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/strbuf.c b/strbuf.c index 9583875..600e27e 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 5397d91..45d25d7 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 -- cgit v0.10.2-6-g49f6