mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-string-ext: simplify str_del_suffix_bang logic
Co-authored-by: Gemini <gemini@google.com>
This commit is contained in:
@@ -1190,15 +1190,10 @@ str_del_suffix_bang(mrb_state *mrb, mrb_value self)
|
||||
struct RString *str = RSTRING(self);
|
||||
|
||||
mrb_get_args(mrb, "s", &ptr, &plen);
|
||||
mrb_check_frozen(mrb, str);
|
||||
mrb_int slen = RSTR_LEN(str);
|
||||
if (plen > slen) return mrb_nil_value();
|
||||
if (!str_suffix_p(mrb, self, ptr, plen)) return mrb_nil_value();
|
||||
if (!mrb_frozen_p(str) && (RSTR_SHARED_P(str) || RSTR_FSHARED_P(str))) {
|
||||
/* no need to modify string */
|
||||
}
|
||||
else {
|
||||
mrb_str_modify(mrb, str);
|
||||
}
|
||||
RSTR_SET_LEN(str, slen-plen);
|
||||
return self;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user