diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-09-26 10:27:11 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-09-26 10:27:11 -0400 |
commit | a6da7938017647dd6e19e23d3d47126cb7a3e1fe (patch) | |
tree | e46c6fd36d800143321b486565ebba79a3bb1f5a /activerecord/lib/active_record | |
parent | 15a8740d68ccf1f376b5f2cf29c5336d8716278f (diff) | |
download | rails-a6da7938017647dd6e19e23d3d47126cb7a3e1fe.tar.gz rails-a6da7938017647dd6e19e23d3d47126cb7a3e1fe.tar.bz2 rails-a6da7938017647dd6e19e23d3d47126cb7a3e1fe.zip |
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.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 2 |
1 files changed, 1 insertions, 1 deletions
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 @@ module ActiveRecord # [ 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 |