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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 19, 2010 at 23:15 UTC
3c0ff44a1ee92bd0f811b95d747a08763983566b
1 file changed
+6
-9
utf8.c
+6
-9
@@ -288,14 +288,11 @@ static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
288
fwrite(buf, len, 1, stdout);
289
}
290
291
-static void print_spaces(struct strbuf *buf, int count)
291
+static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
292
{
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);
296
}
297
298
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,
304
const char *eol = strchrnul(text, '\n');
305
if (*eol == '\n')
306
eol++;
310
- print_spaces(buf, indent);
307
+ strbuf_addchars(buf, ' ', indent);
308
strbuf_write(buf, text, eol - text);
309
text = eol;
310
indent = indent2;
@@ -366,7 +363,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
363
if (space)
364
start = space;
365
else
369
- print_spaces(buf, indent);
366
+ strbuf_addchars(buf, ' ', indent);
367
strbuf_write(buf, start, text - start);
368
if (!c)
369
return w;