From f045e646751bfe0f399aae59746befa6384b96aa Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 23 Jun 2012 13:51:50 +0900 Subject: reduce calling mrb_str_new_cstr() to avoid strlen(); #301 --- src/sprintf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/sprintf.c') 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; -- cgit v1.2.3