mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
+1
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user