From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Git Mailing List <git@vger.kernel.org>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 2/4] utf8.c: remove print_spaces()
Date: Fri, 19 Feb 2010 23:15:55 +0100 [thread overview]
Message-ID: <4B7F0D9B.2060904@lsrfire.ath.cx> (raw)
In-Reply-To: <4B7F0D08.6040608@lsrfire.ath.cx>
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>
---
utf8.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/utf8.c b/utf8.c
index 831cad6..5146d30 100644
--- a/utf8.c
+++ b/utf8.c
@@ -288,14 +288,11 @@ static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
fwrite(buf, len, 1, stdout);
}
-static void print_spaces(struct strbuf *buf, int count)
+static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
- static const char s[] = " ";
- while (count >= sizeof(s)) {
- strbuf_write(buf, s, sizeof(s) - 1);
- count -= sizeof(s) - 1;
- }
- strbuf_write(buf, s, count);
+ strbuf_grow(sb, n);
+ memset(sb->buf + sb->len, c, n);
+ strbuf_setlen(sb, sb->len + n);
}
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,
const char *eol = strchrnul(text, '\n');
if (*eol == '\n')
eol++;
- print_spaces(buf, indent);
+ strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, text, eol - text);
text = eol;
indent = indent2;
@@ -366,7 +363,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
if (space)
start = space;
else
- print_spaces(buf, indent);
+ strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, start, text - start);
if (!c)
return w;
--
1.7.0
next prev parent reply other threads:[~2010-02-19 22:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 22:13 [PATCH 0/4] utf8.c: strbuf'ify strbuf_add_wrapped_text() René Scharfe
2010-02-19 22:15 ` [PATCH 1/4] utf8.c: remove print_wrapped_text() René Scharfe
2010-02-19 22:15 ` René Scharfe [this message]
2010-02-19 22:16 ` [PATCH 3/4] utf8.c: remove strbuf_write() René Scharfe
2010-02-19 22:20 ` [PATCH 4/4] utf8.c: speculatively assume utf-8 in strbuf_add_wrapped_text() René Scharfe
2010-02-20 9:14 ` Johannes Schindelin
2010-02-20 19:22 ` Junio C Hamano
2010-02-20 9:03 ` [PATCH 0/4] utf8.c: strbuf'ify strbuf_add_wrapped_text() Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B7F0D9B.2060904@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.