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

parent 264239f7
......@@ -10,7 +10,7 @@ class Symbol
# Same as <code>sym.to_s.capitalize.intern</code>.
def capitalize
(self.to_s.capitalize! || self).to_sym
self.to_s.capitalize.to_sym
end
##
......@@ -20,7 +20,7 @@ class Symbol
# Same as <code>sym.to_s.downcase.intern</code>.
def downcase
(self.to_s.downcase! || self).to_sym
self.to_s.downcase.to_sym
end
##
......@@ -30,7 +30,7 @@ class Symbol
# Same as <code>sym.to_s.upcase.intern</code>.
def upcase
(self.to_s.upcase! || self).to_sym
self.to_s.upcase.to_sym
end
##
......@@ -41,7 +41,7 @@ class Symbol
def casecmp(other)
return nil unless other.kind_of?(Symbol)
lhs = self.to_s; lhs.upcase!
lhs = self.to_s.upcase
rhs = other.to_s.upcase
lhs <=> rhs
end
......
......@@ -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));
}
......
......@@ -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*
......
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