parse.y: dup iff needed

* parse.y (rb_str_dynamic_intern): dup the given string only if
  needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-03-26 06:34:33 +00:00
parent 9a848c5f4a
commit ad8ed59ab9

View file

@ -10671,7 +10671,6 @@ rb_str_dynamic_intern(VALUE s)
{ {
#if USE_SYMBOL_GC #if USE_SYMBOL_GC
VALUE str = RB_GC_GUARD(s); VALUE str = RB_GC_GUARD(s);
VALUE dup;
rb_encoding *enc, *ascii; rb_encoding *enc, *ascii;
VALUE dsym; VALUE dsym;
ID id, type; ID id, type;
@ -10680,18 +10679,18 @@ rb_str_dynamic_intern(VALUE s)
return ID2SYM(id); return ID2SYM(id);
} }
dup = rb_str_dup(str);
enc = rb_enc_get(str); enc = rb_enc_get(str);
ascii = rb_usascii_encoding(); ascii = rb_usascii_encoding();
if (enc != ascii) { if (enc != ascii) {
if (sym_check_asciionly(str)) { if (sym_check_asciionly(str)) {
str = rb_str_dup(str);
rb_enc_associate(dup, ascii); rb_enc_associate(dup, ascii);
OBJ_FREEZE(str);
} }
} }
type = rb_str_symname_type(str, TRUE); type = rb_str_symname_type(str, TRUE);
OBJ_FREEZE(dup); str = rb_fstring(str);
str = rb_fstring(dup);
dsym = rb_newobj_of(rb_cSymbol, T_SYMBOL); dsym = rb_newobj_of(rb_cSymbol, T_SYMBOL);
OBJ_FREEZE(dsym); OBJ_FREEZE(dsym);
RSYMBOL(dsym)->fstr = str; RSYMBOL(dsym)->fstr = str;