[前][次][番号順一覧][スレッド一覧]

ruby-changes:66594

From: Jeremy <ko1@a...>
Date: Fri, 25 Jun 2021 04:25:45 +0900 (JST)
Subject: [ruby-changes:66594] be230615d0 (master): Remove shift of ep when computing Proc#hash

https://git.ruby-lang.org/ruby.git/commit/?id=be230615d0

From be230615d016e27d5b45b465d1481f6ecf7f1d28 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Tue, 15 Jun 2021 10:06:52 -0700
Subject: 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]
---
 proc.c                 | 2 +-
 test/ruby/test_proc.rb | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/proc.c b/proc.c
index f9e04ce..6e15728 100644
--- a/proc.c
+++ b/proc.c
@@ -1451,7 +1451,7 @@ rb_hash_proc(st_index_t hash, VALUE prc) https://github.com/ruby/ruby/blob/trunk/proc.c#L1451
     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
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 5f2f797..16efd13 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -159,6 +159,15 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L159
     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})
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]