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
+4 -4
View File
@@ -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
+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*