From 657bd31cc74578dfa6002193cf9b98b2b7861a65 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 16 Feb 2025 18:54:08 +0900 Subject: [PATCH] Trivial optimization - Not call `strlen` at the end of the zone name. - Use the initialized UTC string. --- time.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/time.c b/time.c index deb44096af..d19d1873f8 100644 --- a/time.c +++ b/time.c @@ -942,12 +942,14 @@ zone_str(const char *zone) return rb_fstring_lit("(NO-TIMEZONE-ABBREVIATION)"); } - for (p = zone; *p; p++) + for (p = zone; *p; p++) { if (!ISASCII(*p)) { ascii_only = 0; + p += strlen(p); break; } - len = p - zone + strlen(p); + } + len = p - zone; if (ascii_only) { 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))) { VALUE off = INT2FIX(0); int isdst = 0; - zone = rb_fstring_lit("UTC"); + zone = str_utc; # if defined(NEGATIVE_TIME_T) # if SIZEOF_TIME_T <= 4