mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Remove shift of ep when computing Proc#hash
The shift was causing far fewer unique values of hash than expected. Fix pointed out by xtkoba (Tee KOBAYASHI) Fixes [Bug #17951]
This commit is contained in:
parent
3ab68b910f
commit
be230615d0
Notes:
git
2021-06-25 04:25:56 +09:00
2 changed files with 10 additions and 1 deletions
2
proc.c
2
proc.c
|
@ -1451,7 +1451,7 @@ rb_hash_proc(st_index_t hash, VALUE prc)
|
|||
GetProcPtr(prc, proc);
|
||||
hash = rb_hash_uint(hash, (st_index_t)proc->block.as.captured.code.val);
|
||||
hash = rb_hash_uint(hash, (st_index_t)proc->block.as.captured.self);
|
||||
return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep >> 16);
|
||||
return rb_hash_uint(hash, (st_index_t)proc->block.as.captured.ep);
|
||||
}
|
||||
|
||||
MJIT_FUNC_EXPORTED VALUE
|
||||
|
|
|
@ -159,6 +159,15 @@ class TestProc < Test::Unit::TestCase
|
|||
assert_equal(*m_nest{}, "[ruby-core:84583] Feature #14627")
|
||||
end
|
||||
|
||||
def test_hash
|
||||
def self.capture(&block)
|
||||
block
|
||||
end
|
||||
|
||||
procs = Array.new(1000){capture{:foo }}
|
||||
assert_operator(procs.map(&:hash).uniq.size, :>=, 500)
|
||||
end
|
||||
|
||||
def test_block_par
|
||||
assert_equal(10, Proc.new{|&b| b.call(10)}.call {|x| x})
|
||||
assert_equal(12, Proc.new{|a,&b| b.call(a)}.call(12) {|x| x})
|
||||
|
|
Loading…
Add table
Reference in a new issue