string.c: remove code duplication using str_init_modifiable().

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-03-02 15:49:34 +09:00
parent 1a9991f165
commit c3f0f84da5
+1 -6
View File
@@ -827,12 +827,7 @@ mrb_str_to_cstr(mrb_state *mrb, mrb_value str0)
const char *p = RSTRING_PTR(str0);
mrb_int len = RSTRING_LEN(str0);
check_null_byte(mrb, str0);
if (RSTR_EMBEDDABLE_P(len)) {
s = str_init_embed(mrb_obj_alloc_string(mrb), p, len);
}
else {
s = str_init_normal(mrb, mrb_obj_alloc_string(mrb), p, len);
}
s = str_init_modifiable(mrb, mrb_obj_alloc_string(mrb), p, len);
return RSTR_PTR(s);
}