mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
deduplicate static rb_str_format format strings
Anybody who hits these code paths can hit them again in the future, so try deduplicating across multiple runs of these methods to reduce garbage. * string.c (str_upto_each): fstring on "%.*d" * strftime.c (rb_strftime_with_timespec): fstring on "%0*d" git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
312ac7f0a1
commit
9eb94b4dc1
2 changed files with 3 additions and 2 deletions
|
@ -820,7 +820,8 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len,
|
||||||
VALUE args[2], result;
|
VALUE args[2], result;
|
||||||
args[0] = INT2FIX(precision);
|
args[0] = INT2FIX(precision);
|
||||||
args[1] = subsec;
|
args[1] = subsec;
|
||||||
result = rb_str_format(2, args, rb_str_new2("%0*d"));
|
result = rb_str_format(2, args,
|
||||||
|
rb_fstring_cstr("%0*d"));
|
||||||
(void)strlcpy(s, StringValueCStr(result), endp-s);
|
(void)strlcpy(s, StringValueCStr(result), endp-s);
|
||||||
s += precision;
|
s += precision;
|
||||||
}
|
}
|
||||||
|
|
2
string.c
2
string.c
|
@ -4147,7 +4147,7 @@ str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE a
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ID op = excl ? '<' : idLE;
|
ID op = excl ? '<' : idLE;
|
||||||
VALUE args[2], fmt = rb_obj_freeze(rb_usascii_str_new_cstr("%.*d"));
|
VALUE args[2], fmt = rb_fstring_cstr("%.*d");
|
||||||
|
|
||||||
args[0] = INT2FIX(width);
|
args[0] = INT2FIX(width);
|
||||||
while (rb_funcall(b, op, 1, e)) {
|
while (rb_funcall(b, op, 1, e)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue