Merge branch 'rs/use-strbuf-addbuf' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2016 21:21:42 +0000 (14:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Aug 2016 21:21:42 +0000 (14:21 -0700)
Code cleanup.

* rs/use-strbuf-addbuf:
strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf()
use strbuf_addbuf() for appending a strbuf to another

dir.c
path.c
strbuf.c
strbuf.h
wt-status.c
diff --git a/dir.c b/dir.c
index 6172b3438d356d0359c2158708c718c6694e183a..0ea235f3d643d7a9072aca75d7317d1fd7552b4d 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2364,7 +2364,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 259aeed846bd3dac8e10cde30a22ec1ad8697a63..17551c483476050325114b8521f2960707855c59 100644 (file)
--- a/path.c
+++ b/path.c
@@ -483,7 +483,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);
 
index 1ba600bd780733f7a985c88f797efdd93c1e49fa..f3bd5719c636d10780e466e39f1145375c4cab68 100644 (file)
--- 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);
index 83c5c98530700de35bf3e3c3ef6692c4135fec4e..ba8d5f1d465e5b06274028aeb096e325e73e5de4 100644 (file)
--- 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
index 4ce4e35ac3f3542c42c9f71e7bb3f0c5e2c67492..617a28430449b8df19815c31f860338ec98f8c31 100644 (file)
@@ -1062,7 +1062,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]);
                }
        }
        strbuf_list_free(split);