aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-18 04:30:08 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-18 04:30:08 +0000
commite0e5ee7e0c5c854c56acfba2810a759ab0b3f9df (patch)
tree4e89edc3585eb7714e9e4ff42d7573a69f311119 /test
parent5ec93b19bbbadfaffdd47f24d9540c78510abcd9 (diff)
downloadruby-e0e5ee7e0c5c854c56acfba2810a759ab0b3f9df.tar.gz
newhash insn reuses existing keys
This gives the newhash VM instruction the same string reuse capabilities as rb_hash_aset. * st.c (str_key): new wrapper function to call rb_fstring_existing (rb_hash_bulk_insert): use str_key * test/ruby/test_optimization.rb (test_hash_reuse_fstring): ensure key reuse for newhash instructions git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 0d14c9c932..6cf6c63d1b 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -196,6 +196,9 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_predicate h.keys[0], :frozen?
assert_same exp, h.keys[0]
+ h = { key => 1 }
+ assert_same exp, h.keys[0], 'newhash insn should reuse strings, too'
+
h1 = {}
h2 = {}
key.taint
@@ -206,6 +209,10 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_same k1, k2
assert_predicate k1, :tainted?
+ h = { key => 1 }
+ assert_not_predicate key, :frozen?
+ assert_same k1, h.keys[0], 'newhash insn should reuse tainted strings'
+
assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE],
ObjectSpace.memsize_of(k1),
'tainted string should share with untainted fstring'