summaryrefslogtreecommitdiffhomepage
path: root/src/sprintf.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-06-23 13:51:50 +0900
committerYukihiro Matsumoto <[email protected]>2012-06-23 13:51:50 +0900
commitf045e646751bfe0f399aae59746befa6384b96aa (patch)
treef14b8e5b4525fbba488a7e1120a61d48b155da2d /src/sprintf.c
parent1fa63930fd072847d24ffe9c20a57109c41387ec (diff)
downloadmruby-f045e646751bfe0f399aae59746befa6384b96aa.tar.gz
mruby-f045e646751bfe0f399aae59746befa6384b96aa.zip
reduce calling mrb_str_new_cstr() to avoid strlen(); #301
Diffstat (limited to 'src/sprintf.c')
-rw-r--r--src/sprintf.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/sprintf.c b/src/sprintf.c
index e01bf572e..56141e482 100644
--- a/src/sprintf.c
+++ b/src/sprintf.c
@@ -1061,6 +1061,8 @@ static void
fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
{
char *end = buf + size;
+ int n;
+
*buf++ = '%';
if (flags & FSHARP) *buf++ = '#';
if (flags & FPLUS) *buf++ = '+';
@@ -1069,13 +1071,13 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
if (flags & FSPACE) *buf++ = ' ';
if (flags & FWIDTH) {
- snprintf(buf, end - buf, "%d", width);
- buf += strlen(buf);
+ n = snprintf(buf, end - buf, "%d", width);
+ buf += n;
}
if (flags & FPREC) {
- snprintf(buf, end - buf, ".%d", prec);
- buf += strlen(buf);
+ n = snprintf(buf, end - buf, ".%d", prec);
+ buf += n;
}
*buf++ = c;