Using float/double as WTF hash table key is unreliable.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Oct 2012 14:44:53 +0000 (14:44 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Oct 2012 14:44:53 +0000 (14:44 +0000)
commitda36f9ed386d097cc10adbdcf73c26c50d00e9f8
treef3384651e3e0bb6715aa35f69b1c8275ab3879de
parent3b9c08b8c591b9a88a8be13e5c823ccd06d1291e
Using float/double as WTF hash table key is unreliable.
<http://webkit.org/b/98627>

Reviewed by Geoffrey Garen.

Source/WTF:

Change FloatHash::equal() to do a bitwise compare instead of a logical compare.
This fixes a problem where the keys with different binary representation but the
same logical value (e.g 0 and -0) could block each other from being found if they
ended up in the same hash bucket.

* wtf/HashFunctions.h:
(FloatHash):
(WTF::FloatHash::hash):
(WTF::FloatHash::equal):

Tools:

Add a test case checking that using double as the hash table key type won't
have problems distinguishing between keys that are considered equal by operator==
but have different binary representations.

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestDoubleHashTraits):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130639 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/HashFunctions.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp