Implement Ruby2.7's frozen strings from Symbol#to_s.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-10-04 14:42:01 +09:00
parent 264239f78f
commit 08eafe21d3
3 changed files with 12 additions and 7 deletions
+1
View File
@@ -72,6 +72,7 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
}
return;
}
name = mrb_str_dup(mrb, name);
mrb_str_cat_cstr(mrb, name, "::");
mrb_str_cat_cstr(mrb, name, mrb_sym_name(mrb, id));
}
+7 -3
View File
@@ -517,14 +517,18 @@ mrb_sym_str(mrb_state *mrb, mrb_sym sym)
{
mrb_int len;
const char *name = mrb_sym_name_len(mrb, sym, &len);
mrb_value str;
if (!name) return mrb_undef_value(); /* can't happen */
if (SYMBOL_INLINE_P(sym)) {
mrb_value str = mrb_str_new(mrb, name, len);
str = mrb_str_new(mrb, name, len);
RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
return str;
}
return mrb_str_new_static(mrb, name, len);
else {
str = mrb_str_new_static(mrb, name, len);
}
MRB_SET_FROZEN_FLAG(mrb_str_ptr(str));
return str;
}
static const char*