Title: [285572] trunk
Revision
285572
Author
[email protected]
Date
2021-11-10 04:49:25 -0800 (Wed, 10 Nov 2021)

Log Message

Hasher should be able to hash pointers
https://bugs.webkit.org/show_bug.cgi?id=232927

Reviewed by Kimmo Kinnunen.

Source/WTF:

* wtf/Hasher.h:
(WTF::add):

Tools:

* TestWebKitAPI/Tests/WTF/Hasher.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (285571 => 285572)


--- trunk/Source/WTF/ChangeLog	2021-11-10 11:36:04 UTC (rev 285571)
+++ trunk/Source/WTF/ChangeLog	2021-11-10 12:49:25 UTC (rev 285572)
@@ -1,3 +1,13 @@
+2021-11-10  Antti Koivisto  <[email protected]>
+
+        Hasher should be able to hash pointers
+        https://bugs.webkit.org/show_bug.cgi?id=232927
+
+        Reviewed by Kimmo Kinnunen.
+
+        * wtf/Hasher.h:
+        (WTF::add):
+
 2021-11-09  Chris Dumez  <[email protected]>
 
         [macOS] Enable NSURLSession partitioning based on first-party domain at CFNetwork level

Modified: trunk/Source/WTF/wtf/Hasher.h (285571 => 285572)


--- trunk/Source/WTF/wtf/Hasher.h	2021-11-10 11:36:04 UTC (rev 285571)
+++ trunk/Source/WTF/wtf/Hasher.h	2021-11-10 12:49:25 UTC (rev 285572)
@@ -96,6 +96,11 @@
     add(hasher, bitwise_cast<uint32_t>(number));
 }
 
+template<typename T> inline void add(Hasher& hasher, T* ptr)
+{
+    add(hasher, bitwise_cast<uintptr_t>(ptr));
+}
+
 inline void add(Hasher& hasher, const String& string)
 {
     // Chose to hash the characters here. Assuming this is better than hashing the possibly-already-computed hash of the characters.

Modified: trunk/Tools/ChangeLog (285571 => 285572)


--- trunk/Tools/ChangeLog	2021-11-10 11:36:04 UTC (rev 285571)
+++ trunk/Tools/ChangeLog	2021-11-10 12:49:25 UTC (rev 285572)
@@ -1,3 +1,13 @@
+2021-11-10  Antti Koivisto  <[email protected]>
+
+        Hasher should be able to hash pointers
+        https://bugs.webkit.org/show_bug.cgi?id=232927
+
+        Reviewed by Kimmo Kinnunen.
+
+        * TestWebKitAPI/Tests/WTF/Hasher.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-11-09  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r285536.

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp (285571 => 285572)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp	2021-11-10 11:36:04 UTC (rev 285571)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp	2021-11-10 12:49:25 UTC (rev 285572)
@@ -189,6 +189,17 @@
     EXPECT_EQ(1652352321U, computeHash(std::make_pair(std::make_pair(1, 2), std::make_pair(3, 4))));
 }
 
+TEST(WTF, Hasher_pointer)
+{
+    char* nullPtr = nullptr;
+    char* _onePtr_ = nullPtr + 1;
+    char* ffffffPtr = nullPtr + 0xffffff;
+
+    EXPECT_EQ(computeHash(static_cast<uintptr_t>(0)), computeHash(nullPtr));
+    EXPECT_EQ(computeHash(static_cast<uintptr_t>(0x1)), computeHash(onePtr));
+    EXPECT_EQ(computeHash(static_cast<uintptr_t>(0xffffff)), computeHash(ffffffPtr));
+}
+
 struct HasherAddCustom1 { };
 
 void add(Hasher& hasher, const HasherAddCustom1&)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to