Skip to content

Commit bdeee70

Browse files
committed
Avoid allocating intermediate string in zone_str
1 parent 3cd3081 commit bdeee70

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

benchmark/time_now.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
benchmark:
22
- 'Time.now'
33
- 'Time.now(in: "+09:00")'
4+
- 'Time.now.year'

time.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,6 @@ zone_str(const char *zone)
981981
{
982982
const char *p;
983983
int ascii_only = 1;
984-
VALUE str;
985984
size_t len;
986985

987986
if (zone == NULL) {
@@ -997,18 +996,18 @@ zone_str(const char *zone)
997996
}
998997
len = p - zone;
999998
if (ascii_only) {
1000-
str = rb_usascii_str_new(zone, len);
999+
return rb_enc_interned_str(zone, len, rb_usascii_encoding());
10011000
}
10021001
else {
10031002
#ifdef _WIN32
1004-
str = rb_utf8_str_new(zone, len);
1003+
VALUE str = rb_utf8_str_new(zone, len);
10051004
/* until we move to UTF-8 on Windows completely */
10061005
str = rb_str_export_locale(str);
1006+
return rb_fstring(str);
10071007
#else
1008-
str = rb_enc_str_new(zone, len, rb_locale_encoding());
1008+
return rb_enc_interned_str(zone, len, rb_locale_encoding());
10091009
#endif
10101010
}
1011-
return rb_fstring(str);
10121011
}
10131012

10141013
static void

0 commit comments

Comments
 (0)