Unverified Commit 74310f41 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4826 from shuujii/revert-Implement-Ruby2.7-frozen-strings-from-Symbol-to_s

Revert "Implement Ruby2.7's frozen strings from `Symbol#to_s`"
parents c9f156ef a367373f
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
static mrb_value static mrb_value
mrb_mod_name(mrb_state *mrb, mrb_value self) mrb_mod_name(mrb_state *mrb, mrb_value self)
{ {
return mrb_class_path(mrb, mrb_class_ptr(self)); mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self));
if (mrb_string_p(name)) {
MRB_SET_FROZEN_FLAG(mrb_basic_ptr(name));
}
return name;
} }
static mrb_value static mrb_value
......
...@@ -10,7 +10,7 @@ class Symbol ...@@ -10,7 +10,7 @@ class Symbol
# Same as <code>sym.to_s.capitalize.intern</code>. # Same as <code>sym.to_s.capitalize.intern</code>.
def capitalize def capitalize
self.to_s.capitalize.to_sym (self.to_s.capitalize! || self).to_sym
end end
## ##
...@@ -20,7 +20,7 @@ class Symbol ...@@ -20,7 +20,7 @@ class Symbol
# Same as <code>sym.to_s.downcase.intern</code>. # Same as <code>sym.to_s.downcase.intern</code>.
def downcase def downcase
self.to_s.downcase.to_sym (self.to_s.downcase! || self).to_sym
end end
## ##
...@@ -30,7 +30,7 @@ class Symbol ...@@ -30,7 +30,7 @@ class Symbol
# Same as <code>sym.to_s.upcase.intern</code>. # Same as <code>sym.to_s.upcase.intern</code>.
def upcase def upcase
self.to_s.upcase.to_sym (self.to_s.upcase! || self).to_sym
end end
## ##
...@@ -41,7 +41,7 @@ class Symbol ...@@ -41,7 +41,7 @@ class Symbol
def casecmp(other) def casecmp(other)
return nil unless other.kind_of?(Symbol) return nil unless other.kind_of?(Symbol)
lhs = self.to_s.upcase lhs = self.to_s; lhs.upcase!
rhs = other.to_s.upcase rhs = other.to_s.upcase
lhs <=> rhs lhs <=> rhs
end end
......
...@@ -65,23 +65,21 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb ...@@ -65,23 +65,21 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
name = mrb_symbol_value(id); name = mrb_symbol_value(id);
} }
else { else {
const char *n; name = mrb_class_path(mrb, outer);
mrb_int len; if (mrb_nil_p(name)) { /* unnamed outer class */
mrb_value outer_name = mrb_class_path(mrb, outer);
if (mrb_nil_p(outer_name)) { /* unnamed outer class */
if (outer != mrb->object_class && outer != c) { if (outer != mrb->object_class && outer != c) {
mrb_obj_iv_set_force(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"), mrb_obj_iv_set_force(mrb, (struct RObject*)c, mrb_intern_lit(mrb, "__outer__"),
mrb_obj_value(outer)); mrb_obj_value(outer));
} }
return; return;
} }
n = mrb_sym_name_len(mrb, id, &len); else {
name = mrb_str_new_capa(mrb, RSTRING_LEN(outer_name) + 2 + len); mrb_int len;
mrb_str_cat_str(mrb, name, outer_name); const char *n = mrb_sym_name_len(mrb, id, &len);
mrb_str_cat_lit(mrb, name, "::"); mrb_str_cat_lit(mrb, name, "::");
mrb_str_cat(mrb, name, n, len); mrb_str_cat(mrb, name, n, len);
MRB_SET_FROZEN_FLAG(mrb_obj_ptr(name)); }
} }
mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name); mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name);
} }
...@@ -1718,7 +1716,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c) ...@@ -1718,7 +1716,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
/* toplevel class/module */ /* toplevel class/module */
return mrb_sym_str(mrb, mrb_symbol(path)); return mrb_sym_str(mrb, mrb_symbol(path));
} }
return path; return mrb_str_dup(mrb, path);
} }
MRB_API struct RClass* MRB_API struct RClass*
...@@ -1885,8 +1883,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) ...@@ -1885,8 +1883,7 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
return mrb_str_cat_lit(mrb, str, ">"); return mrb_str_cat_lit(mrb, str, ">");
} }
else { else {
mrb_value str = class_name_str(mrb, mrb_class_ptr(klass)); return class_name_str(mrb, mrb_class_ptr(klass));
return mrb_frozen_p(mrb_basic_ptr(str)) ? mrb_str_dup(mrb, str) : str;
} }
} }
......
...@@ -517,18 +517,14 @@ mrb_sym_str(mrb_state *mrb, mrb_sym sym) ...@@ -517,18 +517,14 @@ mrb_sym_str(mrb_state *mrb, mrb_sym sym)
{ {
mrb_int len; mrb_int len;
const char *name = mrb_sym_name_len(mrb, sym, &len); const char *name = mrb_sym_name_len(mrb, sym, &len);
mrb_value str;
if (!name) return mrb_undef_value(); /* can't happen */ if (!name) return mrb_undef_value(); /* can't happen */
if (SYMBOL_INLINE_P(sym)) { if (SYMBOL_INLINE_P(sym)) {
str = mrb_str_new(mrb, name, len); mrb_value str = mrb_str_new(mrb, name, len);
RSTR_SET_ASCII_FLAG(mrb_str_ptr(str)); RSTR_SET_ASCII_FLAG(mrb_str_ptr(str));
}
else {
str = mrb_str_new_static(mrb, name, len);
}
MRB_SET_FROZEN_FLAG(mrb_str_ptr(str));
return str; return str;
}
return mrb_str_new_static(mrb, name, len);
} }
static const char* static const char*
......
...@@ -1123,7 +1123,7 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c) ...@@ -1123,7 +1123,7 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c)
iv_del(mrb, c->iv, mrb_intern_lit(mrb, "__outer__"), NULL); iv_del(mrb, c->iv, mrb_intern_lit(mrb, "__outer__"), NULL);
iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path); iv_put(mrb, c->iv, mrb_intern_lit(mrb, "__classname__"), path);
mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path); mrb_field_write_barrier_value(mrb, (struct RBasic*)c, path);
MRB_SET_FROZEN_FLAG(mrb_obj_ptr(path)); path = mrb_str_dup(mrb, path);
} }
return path; return path;
} }
......
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