Skip to content

Commit 3c0ff44

Browse files
René Scharfegitster
authored andcommitted
utf8.c: remove print_spaces()
The previous patch made sure that strbuf_add_wrapped_text() (and thus strbuf_add_indented_text(), too) always get a strbuf. Make use of this fact by adding strbuf_addchars(), a small helper that adds a char the specified number of times to a strbuf, and use it to replace print_spaces(). Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb96a2c commit 3c0ff44

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

utf8.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,11 @@ static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
288288
fwrite(buf, len, 1, stdout);
289289
}
290290

291-
static void print_spaces(struct strbuf *buf, int count)
291+
static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
292292
{
293-
static const char s[] = " ";
294-
while (count >= sizeof(s)) {
295-
strbuf_write(buf, s, sizeof(s) - 1);
296-
count -= sizeof(s) - 1;
297-
}
298-
strbuf_write(buf, s, count);
293+
strbuf_grow(sb, n);
294+
memset(sb->buf + sb->len, c, n);
295+
strbuf_setlen(sb, sb->len + n);
299296
}
300297

301298
static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
@@ -307,7 +304,7 @@ static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
307304
const char *eol = strchrnul(text, '\n');
308305
if (*eol == '\n')
309306
eol++;
310-
print_spaces(buf, indent);
307+
strbuf_addchars(buf, ' ', indent);
311308
strbuf_write(buf, text, eol - text);
312309
text = eol;
313310
indent = indent2;
@@ -366,7 +363,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
366363
if (space)
367364
start = space;
368365
else
369-
print_spaces(buf, indent);
366+
strbuf_addchars(buf, ' ', indent);
370367
strbuf_write(buf, start, text - start);
371368
if (!c)
372369
return w;

0 commit comments

Comments
 (0)