strbuf: add and use strbuf_insertstr()

Add a function for inserting a C string into a strbuf.  Use it
throughout the source to get rid of magic string length constants and
explicit strlen() calls.

Like strbuf_addstr(), implement it as an inline function to avoid the
implicit strlen() calls to cause runtime overhead.

Helped-by: Taylor Blau <me@ttaylorr.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2020-02-09 14:44:23 +01:00
committed by Junio C Hamano
parent d0654dc308
commit a91cc7fad0
11 changed files with 27 additions and 15 deletions

View File

@ -1581,9 +1581,9 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
strbuf_setlen(sb, sb->len - 1);
} else if (orig_len != sb->len) {
if (magic == ADD_LF_BEFORE_NON_EMPTY)
strbuf_insert(sb, orig_len, "\n", 1);
strbuf_insertstr(sb, orig_len, "\n");
else if (magic == ADD_SP_BEFORE_NON_EMPTY)
strbuf_insert(sb, orig_len, " ", 1);
strbuf_insertstr(sb, orig_len, " ");
}
return consumed + 1;
}