Title: [287120] trunk/Source
Revision
287120
Author
cdu...@apple.com
Date
2021-12-15 17:18:05 -0800 (Wed, 15 Dec 2021)

Log Message

Support passing an old-style enum to add(Hasher&, ...)
https://bugs.webkit.org/show_bug.cgi?id=234368

Reviewed by Darin Adler.

Source/WebCore:

Drop static_casts that should no longer be needed now that we can pass
an enum to add(Hasher&, ...).

* platform/network/ProtectionSpaceHash.h:
(WebCore::ProtectionSpaceHash::hash):

Source/WTF:

Support passing an old-style enum to add(Hasher&, ...). Previously, it would work for enum classes
but lead to ambiguity errors with some compiler when passing a plain enum.

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

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (287119 => 287120)


--- trunk/Source/WTF/ChangeLog	2021-12-16 01:08:06 UTC (rev 287119)
+++ trunk/Source/WTF/ChangeLog	2021-12-16 01:18:05 UTC (rev 287120)
@@ -1,3 +1,17 @@
+2021-12-15  Chris Dumez  <cdu...@apple.com>
+
+        Support passing an old-style enum to add(Hasher&, ...)
+        https://bugs.webkit.org/show_bug.cgi?id=234368
+
+        Reviewed by Darin Adler.
+
+        Support passing an old-style enum to add(Hasher&, ...). Previously, it would work for enum classes
+        but lead to ambiguity errors with some compiler when passing a plain enum.
+
+        * wtf/Hasher.h:
+        (WTF::Hasher::add):
+        (WTF::add):
+
 2021-12-15  Jer Noble  <jer.no...@apple.com>
 
         [Mac] Adopt -[NSScreen safeAreaInsets]

Modified: trunk/Source/WTF/wtf/Hasher.h (287119 => 287120)


--- trunk/Source/WTF/wtf/Hasher.h	2021-12-16 01:08:06 UTC (rev 287119)
+++ trunk/Source/WTF/wtf/Hasher.h	2021-12-16 01:18:05 UTC (rev 287120)
@@ -31,7 +31,7 @@
 
 template<typename... Types> uint32_t computeHash(const Types&...);
 template<typename T, typename... OtherTypes> uint32_t computeHash(std::initializer_list<T>, std::initializer_list<OtherTypes>...);
-template<typename UnsignedInteger> std::enable_if_t<std::is_unsigned<UnsignedInteger>::value && sizeof(UnsignedInteger) <= sizeof(uint32_t), void> add(Hasher&, UnsignedInteger);
+template<typename UnsignedInteger> std::enable_if_t<std::is_unsigned_v<UnsignedInteger> && sizeof(UnsignedInteger) <= sizeof(uint32_t) && !std::is_enum_v<UnsignedInteger>, void> add(Hasher&, UnsignedInteger);
 
 class Hasher {
     WTF_MAKE_FAST_ALLOCATED;
@@ -51,7 +51,7 @@
         return hasher.m_underlyingHasher.hash();
     }
 
-    template<typename UnsignedInteger> friend std::enable_if_t<std::is_unsigned<UnsignedInteger>::value && sizeof(UnsignedInteger) <= sizeof(uint32_t), void> add(Hasher& hasher, UnsignedInteger integer)
+    template<typename UnsignedInteger> friend std::enable_if_t<std::is_unsigned_v<UnsignedInteger> && sizeof(UnsignedInteger) <= sizeof(uint32_t) && !std::is_enum_v<UnsignedInteger>, void> add(Hasher& hasher, UnsignedInteger integer)
     {
         // We can consider adding a more efficient code path for hashing booleans or individual bytes if needed.
         // We can consider adding a more efficient code path for hashing 16-bit values if needed, perhaps using addCharacter,
@@ -123,7 +123,7 @@
     add(hasher, url.string());
 }
 
-template<typename Enumeration> std::enable_if_t<std::is_enum<Enumeration>::value, void> add(Hasher& hasher, Enumeration value)
+template<typename Enumeration> std::enable_if_t<std::is_enum_v<Enumeration>, void> add(Hasher& hasher, Enumeration value)
 {
     add(hasher, static_cast<std::underlying_type_t<Enumeration>>(value));
 }

Modified: trunk/Source/WebCore/ChangeLog (287119 => 287120)


--- trunk/Source/WebCore/ChangeLog	2021-12-16 01:08:06 UTC (rev 287119)
+++ trunk/Source/WebCore/ChangeLog	2021-12-16 01:18:05 UTC (rev 287120)
@@ -1,3 +1,16 @@
+2021-12-15  Chris Dumez  <cdu...@apple.com>
+
+        Support passing an old-style enum to add(Hasher&, ...)
+        https://bugs.webkit.org/show_bug.cgi?id=234368
+
+        Reviewed by Darin Adler.
+
+        Drop static_casts that should no longer be needed now that we can pass
+        an enum to add(Hasher&, ...).
+
+        * platform/network/ProtectionSpaceHash.h:
+        (WebCore::ProtectionSpaceHash::hash):
+
 2021-12-15  Alexey Shvayka  <ashva...@apple.com>
 
         [WebIDL] Remove the now-unused "ExecState" value of [CallWith] extended attribute

Modified: trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h (287119 => 287120)


--- trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h	2021-12-16 01:08:06 UTC (rev 287119)
+++ trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h	2021-12-16 01:18:05 UTC (rev 287120)
@@ -37,8 +37,8 @@
         Hasher hasher;
         add(hasher, protectionSpace.host());
         add(hasher, protectionSpace.port());
-        add(hasher, static_cast<unsigned>(protectionSpace.serverType()));
-        add(hasher, static_cast<unsigned>(protectionSpace.authenticationScheme()));
+        add(hasher, protectionSpace.serverType());
+        add(hasher, protectionSpace.authenticationScheme());
         if (!protectionSpace.isProxy())
             add(hasher, protectionSpace.realm());
         return hasher.hash();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to