Skip to content

Commit b4e8a84

Browse files
committed
Merge branch 'rs/use-strbuf-addbuf'
Code cleanup. * rs/use-strbuf-addbuf: strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf() use strbuf_addbuf() for appending a strbuf to another
2 parents 7b01ab5 + 31471ba commit b4e8a84

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
23642364

23652365
varint_len = encode_varint(untracked->ident.len, varbuf);
23662366
strbuf_add(out, varbuf, varint_len);
2367-
strbuf_add(out, untracked->ident.buf, untracked->ident.len);
2367+
strbuf_addbuf(out, &untracked->ident);
23682368

23692369
strbuf_add(out, ouc, ouc_size(len));
23702370
free(ouc);

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
483483
strbuf_addstr(buf, git_dir);
484484
}
485485
strbuf_addch(buf, '/');
486-
strbuf_addstr(&git_submodule_dir, buf->buf);
486+
strbuf_addbuf(&git_submodule_dir, buf);
487487

488488
strbuf_vaddf(buf, fmt, args);
489489

strbuf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len)
197197
strbuf_setlen(sb, sb->len + len);
198198
}
199199

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+
200207
void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
201208
{
202209
strbuf_grow(sb, len);

strbuf.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
263263
/**
264264
* Copy the contents of another buffer at the end of the current one.
265265
*/
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);
271267

272268
/**
273269
* Copy part of the buffer from a given position till a given length to the

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ static void abbrev_sha1_in_line(struct strbuf *line)
10631063
strbuf_addf(split[1], "%s ", abbrev);
10641064
strbuf_reset(line);
10651065
for (i = 0; split[i]; i++)
1066-
strbuf_addf(line, "%s", split[i]->buf);
1066+
strbuf_addbuf(line, split[i]);
10671067
}
10681068
}
10691069
strbuf_list_free(split);

0 commit comments

Comments
 (0)