From 9135f0991b9b83fbd7980968348c7f17ff2930b3 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 9 Jan 2024 11:44:12 +0900 Subject: [PATCH] string.c: avoid RSTRING_CHAR_LEN() if possible Current code scan the string twice (once from RSTRING_CHAR_LEN, and once from chars2bytes), but those scans are not necessary. Just point the end of the string. --- src/string.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/string.c b/src/string.c index f4011756f..562a62bd7 100644 --- a/src/string.c +++ b/src/string.c @@ -2070,8 +2070,7 @@ mrb_str_rindex_m(mrb_state *mrb, mrb_value str) mrb_int pos; if (mrb_get_args(mrb, "S|i", &sub, &pos) == 1) { - pos = RSTRING_CHAR_LEN(str); - pos = chars2bytes(str, 0, pos); + pos = RSTRING_LEN(str); } else if (pos >= 0) { pos = chars2bytes(str, 0, pos);