summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwatson1978 <watson1978@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-20 09:23:46 +0000
committerwatson1978 <watson1978@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-20 09:23:46 +0000
commit9cd66d7022aa2b8aff719a26c594efc9c3797ec1 (patch)
treed31def5bda9ccd953ed4b674993d9ec023a5cbd7
parent35c54a11b30342b3ffa72b476347c5b9998f2d79 (diff)
Improve Hash#merge performance
* hash.c (rb_hash_merge): use rb_hash_dup() instead of rb_obj_dup() to duplicate Hash object. rb_hash_dup() is faster duplicating function for Hash object which got rid of Hash#initialize_dup method calling. Hash#merge will be faster around 60%. [ruby-dev:50026] [Bug #13343] [Fix GH-1533] ### Before user system total real Hash#merge 0.160000 0.020000 0.180000 ( 0.182357) ### After user system total real Hash#merge 0.110000 0.010000 0.120000 ( 0.114404) ### Test code require 'benchmark' Benchmark.bmbm do |x| hash1 = {} 100.times { |i| hash1[i.to_s] = i } hash2 = {} 100.times { |i| hash2[(i*2).to_s] = i*2 } x.report "Hash#merge" do 10000.times do hash1.merge(hash2) end end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--hash.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 60c491f14e..d616e8e90e 100644
--- a/hash.c
+++ b/hash.c
@@ -2496,7 +2496,7 @@ rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func)
static VALUE
rb_hash_merge(VALUE hash1, VALUE hash2)
{
- return rb_hash_update(rb_obj_dup(hash1), hash2);
+ return rb_hash_update(rb_hash_dup(hash1), hash2);
}
static int