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:
committed by
Junio C Hamano
parent
d0654dc308
commit
a91cc7fad0
4
pretty.c
4
pretty.c
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user