Trivial optimization

- Not call `strlen` at the end of the zone name.
- Use the initialized UTC string.
This commit is contained in:
Nobuyoshi Nakada 2025-02-16 18:54:08 +09:00
parent 64eba7a01a
commit 657bd31cc7
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

8
time.c
View File

@ -942,12 +942,14 @@ zone_str(const char *zone)
return rb_fstring_lit("(NO-TIMEZONE-ABBREVIATION)"); return rb_fstring_lit("(NO-TIMEZONE-ABBREVIATION)");
} }
for (p = zone; *p; p++) for (p = zone; *p; p++) {
if (!ISASCII(*p)) { if (!ISASCII(*p)) {
ascii_only = 0; ascii_only = 0;
p += strlen(p);
break; break;
} }
len = p - zone + strlen(p); }
len = p - zone;
if (ascii_only) { if (ascii_only) {
str = rb_usascii_str_new(zone, len); str = rb_usascii_str_new(zone, len);
} }
@ -1442,7 +1444,7 @@ guess_local_offset(struct vtm *vtm_utc, int *isdst_ret, VALUE *zone_ret)
if (lt(vtm_utc->year, INT2FIX(1916))) { if (lt(vtm_utc->year, INT2FIX(1916))) {
VALUE off = INT2FIX(0); VALUE off = INT2FIX(0);
int isdst = 0; int isdst = 0;
zone = rb_fstring_lit("UTC"); zone = str_utc;
# if defined(NEGATIVE_TIME_T) # if defined(NEGATIVE_TIME_T)
# if SIZEOF_TIME_T <= 4 # if SIZEOF_TIME_T <= 4