mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
reduce calling mrb_str_new_cstr() to avoid strlen(); #301
This commit is contained in:
+6
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user