提交 a6da7938 编写于 作者: S Sean Griffin

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.
上级 15a8740d
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册