Refactor of String#end_with? comparison logic.

parent a0183b39
...@@ -141,14 +141,13 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self) ...@@ -141,14 +141,13 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
size_t len_l, len_r, len_cmp; size_t len_l, len_r;
len_l = RSTRING_LEN(self); len_l = RSTRING_LEN(self);
len_r = RSTRING_LEN(argv[i]); len_r = RSTRING_LEN(argv[i]);
if (len_l >= len_r) { if (len_l >= len_r) {
len_cmp = (len_l > len_r) ? len_r : len_l; if (memcmp(RSTRING_PTR(self) + (len_l - len_r),
if (memcmp(RSTRING_PTR(self) + (len_l - len_cmp), RSTRING_PTR(argv[i]),
RSTRING_PTR(argv[i]) + (len_r - len_cmp), len_r) == 0) {
len_cmp) == 0) {
return mrb_true_value(); return mrb_true_value();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment