mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[EXPERIMENTAL] Make Symbol#to_s return a frozen String
* Always the same frozen String for a given Symbol. * Avoids extra allocations whenever calling Symbol#to_s. * See [Feature #16150]
This commit is contained in:
parent
4a4c502825
commit
6ffc045a81
Notes:
git
2019-09-26 17:23:27 +09:00
4 changed files with 31 additions and 3 deletions
|
@ -6,4 +6,21 @@ describe :symbol_id2name, shared: true do
|
|||
:@ruby.send(@method).should == "@ruby"
|
||||
:@@ruby.send(@method).should == "@@ruby"
|
||||
end
|
||||
|
||||
ruby_version_is "2.7" do
|
||||
it "returns a frozen String" do
|
||||
:my_symbol.to_s.frozen?.should == true
|
||||
:"dynamic symbol #{6 * 7}".to_s.frozen?.should == true
|
||||
end
|
||||
|
||||
it "always returns the same String for a given Symbol" do
|
||||
s1 = :my_symbol.to_s
|
||||
s2 = :my_symbol.to_s
|
||||
s1.should equal(s2)
|
||||
|
||||
s1 = :"dynamic symbol #{6 * 7}".to_s
|
||||
s2 = :"dynamic symbol #{2 * 3 * 7}".to_s
|
||||
s1.should equal(s2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue