From a6da7938017647dd6e19e23d3d47126cb7a3e1fe Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 26 Sep 2016 10:27:11 -0400 Subject: [PATCH] Use xor to avoid allocations in `AR::Core#hash` This is not as good a solution as actually hashing both values, but Ruby doesn't expose that capability other than allocating the array. Unless we were to do something silly like have a thread local array that is re-used, I don't see any other way to do this without allocation. This solution may not be perfect, but it should reasonably avoid collisions to the extent that we need. --- activerecord/lib/active_record/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 3465b68ac6..622df0cfc1 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -452,7 +452,7 @@ def ==(comparison_object) # [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ] def hash if id - [self.class, id].hash + self.class.hash ^ self.id.hash else super end -- GitLab