Title: [294789] trunk/Source/WebCore/svg
Revision
294789
Author
simon.fra...@apple.com
Date
2022-05-24 22:57:54 -0700 (Tue, 24 May 2022)

Log Message

Simplify SVGPropertyOwnerRegistry slightly
https://bugs.webkit.org/show_bug.cgi?id=240839

Reviewed by Yusuke Suzuki.

SVGPropertyOwnerRegistry::findAccessor() had to loop through the hash table entries
because it wanted the behavior of QualifiedName::matches(), which is different from
QualifiedName::operator==. However, we can achieve this by using hash traits, and
the appropriate traits already exist in the form of SVGAttributeHashTranslator.

* Source/WebCore/svg/SVGElementInlines.h:
(WebCore::SVGAttributeHashTranslator::hash): Deleted.
(WebCore::SVGAttributeHashTranslator::equal): Deleted.
* Source/WebCore/svg/properties/SVGPropertyOwnerRegistry.h:
(WebCore::SVGAttributeHashTranslator::hash):
(WebCore::SVGAttributeHashTranslator::equal):
(WebCore::SVGPropertyOwnerRegistry::attributeNameToAccessorMap):
(WebCore::SVGPropertyOwnerRegistry::findAccessor):

Canonical link: https://commits.webkit.org/250948@main

Modified Paths

Diff

Modified: trunk/Source/WebCore/svg/SVGElementInlines.h (294788 => 294789)


--- trunk/Source/WebCore/svg/SVGElementInlines.h	2022-05-25 04:43:31 UTC (rev 294788)
+++ trunk/Source/WebCore/svg/SVGElementInlines.h	2022-05-25 05:57:54 UTC (rev 294789)
@@ -41,18 +41,6 @@
     invalidateStyle();
 }
 
-struct SVGAttributeHashTranslator {
-    static unsigned hash(const QualifiedName& key)
-    {
-        if (key.hasPrefix()) {
-            QualifiedNameComponents components = { nullAtom().impl(), key.localName().impl(), key.namespaceURI().impl() };
-            return computeHash(components);
-        }
-        return DefaultHash<QualifiedName>::hash(key);
-    }
-    static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
-};
-
 inline bool Element::hasTagName(const SVGQualifiedName& tagName) const
 {
     return ContainerNode::hasTagName(tagName);

Modified: trunk/Source/WebCore/svg/properties/SVGPropertyOwnerRegistry.h (294788 => 294789)


--- trunk/Source/WebCore/svg/properties/SVGPropertyOwnerRegistry.h	2022-05-25 04:43:31 UTC (rev 294788)
+++ trunk/Source/WebCore/svg/properties/SVGPropertyOwnerRegistry.h	2022-05-25 05:57:54 UTC (rev 294789)
@@ -35,6 +35,21 @@
 
 class SVGAttributeAnimator;
 
+struct SVGAttributeHashTranslator {
+    static unsigned hash(const QualifiedName& key)
+    {
+        if (key.hasPrefix()) {
+            QualifiedNameComponents components = { nullAtom().impl(), key.localName().impl(), key.namespaceURI().impl() };
+            return computeHash(components);
+        }
+        return DefaultHash<QualifiedName>::hash(key);
+    }
+    static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
+
+    static constexpr bool safeToCompareToEmptyOrDeleted = false;
+    static constexpr bool hasHashInValue = true;
+};
+
 template<typename OwnerType, typename... BaseTypes>
 class SVGPropertyOwnerRegistry : public SVGPropertyRegistry {
 public:
@@ -300,9 +315,11 @@
 
 private:
     // Singleton map for every OwnerType.
-    static HashMap<QualifiedName, const SVGMemberAccessor<OwnerType>*>& attributeNameToAccessorMap()
+    using QualifiedNameAccessorHashMap = HashMap<QualifiedName, const SVGMemberAccessor<OwnerType>*, SVGAttributeHashTranslator>;
+
+    static QualifiedNameAccessorHashMap& attributeNameToAccessorMap()
     {
-        static NeverDestroyed<HashMap<QualifiedName, const SVGMemberAccessor<OwnerType>*>> attributeNameToAccessorMap;
+        static NeverDestroyed<QualifiedNameAccessorHashMap> attributeNameToAccessorMap;
         return attributeNameToAccessorMap;
     }
 
@@ -331,12 +348,7 @@
 
     static const SVGMemberAccessor<OwnerType>* findAccessor(const QualifiedName& attributeName)
     {
-        // Here we need to loop through the entries in the map and use matches() to compare them with attributeName.
-        // m_map.contains() uses QualifiedName::operator==() which compares the impl pointers only while matches()
-        // compares the contents if the impl pointers differ.
-        auto it = std::find_if(attributeNameToAccessorMap().begin(), attributeNameToAccessorMap().end(), [&attributeName](const auto& entry) -> bool {
-            return entry.key.matches(attributeName);
-        });
+        auto it = attributeNameToAccessorMap().find(attributeName);
         return it != attributeNameToAccessorMap().end() ? it->value : nullptr;
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to