Title: [164854] trunk/Source/WebCore
Revision
164854
Author
[email protected]
Date
2014-02-27 21:54:09 -0800 (Thu, 27 Feb 2014)

Log Message

Unify the three call sites of SelectorQueryCache
https://bugs.webkit.org/show_bug.cgi?id=129249

Reviewed by Andreas Kling.

The three call sites of SelectorQueryCache were doing the exact same thing.
That code is mvoed to a new function Document::selectorQueryForString().

Also use String instead of AtomicString for querySelector() and querySelectorAll().
This prevent the call sites from creating AtomicString just for the time of the call.
This causes a tiny slow down on microbenchmarks that continuously query the same string
but has no negative impact on realistic/good test cases (and the bindings are simplified).

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::querySelector):
(WebCore::ContainerNode::querySelectorAll):
* dom/ContainerNode.h:
* dom/Document.cpp:
(WebCore::Document::selectorQueryForString):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::webkitMatchesSelector):
* dom/SelectorQuery.cpp:
(WebCore::SelectorQueryCache::add):
* dom/SelectorQuery.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (164853 => 164854)


--- trunk/Source/WebCore/ChangeLog	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/ChangeLog	2014-02-28 05:54:09 UTC (rev 164854)
@@ -1,3 +1,31 @@
+2014-02-27  Benjamin Poulain  <[email protected]>
+
+        Unify the three call sites of SelectorQueryCache
+        https://bugs.webkit.org/show_bug.cgi?id=129249
+
+        Reviewed by Andreas Kling.
+
+        The three call sites of SelectorQueryCache were doing the exact same thing.
+        That code is mvoed to a new function Document::selectorQueryForString().
+
+        Also use String instead of AtomicString for querySelector() and querySelectorAll().
+        This prevent the call sites from creating AtomicString just for the time of the call.
+        This causes a tiny slow down on microbenchmarks that continuously query the same string
+        but has no negative impact on realistic/good test cases (and the bindings are simplified).
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::querySelector):
+        (WebCore::ContainerNode::querySelectorAll):
+        * dom/ContainerNode.h:
+        * dom/Document.cpp:
+        (WebCore::Document::selectorQueryForString):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::webkitMatchesSelector):
+        * dom/SelectorQuery.cpp:
+        (WebCore::SelectorQueryCache::add):
+        * dom/SelectorQuery.h:
+
 2014-02-27  Ryosuke Niwa  <[email protected]>
 
         JSC ignores the extra memory cost of HTMLCollection after a major GC

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (164853 => 164854)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2014-02-28 05:54:09 UTC (rev 164854)
@@ -1071,30 +1071,18 @@
     setAttributeEventListener(eventType, JSLazyEventListener::createForNode(*this, attributeName, attributeValue));
 }
 
-Element* ContainerNode::querySelector(const AtomicString& selectors, ExceptionCode& ec)
+Element* ContainerNode::querySelector(const String& selectors, ExceptionCode& ec)
 {
-    if (selectors.isEmpty()) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
-
-    SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors, document(), ec);
-    if (!selectorQuery)
-        return nullptr;
-    return selectorQuery->queryFirst(*this);
+    if (SelectorQuery* selectorQuery = document().selectorQueryForString(selectors, ec))
+        return selectorQuery->queryFirst(*this);
+    return nullptr;
 }
 
-RefPtr<NodeList> ContainerNode::querySelectorAll(const AtomicString& selectors, ExceptionCode& ec)
+RefPtr<NodeList> ContainerNode::querySelectorAll(const String& selectors, ExceptionCode& ec)
 {
-    if (selectors.isEmpty()) {
-        ec = SYNTAX_ERR;
-        return nullptr;
-    }
-
-    SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors, document(), ec);
-    if (!selectorQuery)
-        return nullptr;
-    return selectorQuery->queryAll(*this);
+    if (SelectorQuery* selectorQuery = document().selectorQueryForString(selectors, ec))
+        return selectorQuery->queryAll(*this);
+    return nullptr;
 }
 
 PassRefPtr<NodeList> ContainerNode::getElementsByTagName(const AtomicString& localName)

Modified: trunk/Source/WebCore/dom/ContainerNode.h (164853 => 164854)


--- trunk/Source/WebCore/dom/ContainerNode.h	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2014-02-28 05:54:09 UTC (rev 164854)
@@ -128,8 +128,8 @@
 
     RenderElement* renderer() const;
 
-    Element* querySelector(const AtomicString& selectors, ExceptionCode&);
-    RefPtr<NodeList> querySelectorAll(const AtomicString& selectors, ExceptionCode&);
+    Element* querySelector(const String& selectors, ExceptionCode&);
+    RefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&);
 
     PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
     PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);

Modified: trunk/Source/WebCore/dom/Document.cpp (164853 => 164854)


--- trunk/Source/WebCore/dom/Document.cpp	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-02-28 05:54:09 UTC (rev 164854)
@@ -752,11 +752,16 @@
     return m_imagesByUsemap.getElementByLowercasedUsemap(name, *this);
 }
 
-SelectorQueryCache& Document::selectorQueryCache()
+SelectorQuery* Document::selectorQueryForString(const String& selectorString, ExceptionCode& ec)
 {
+    if (selectorString.isEmpty()) {
+        ec = SYNTAX_ERR;
+        return nullptr;
+    }
+
     if (!m_selectorQueryCache)
         m_selectorQueryCache = std::make_unique<SelectorQueryCache>();
-    return *m_selectorQueryCache;
+    return m_selectorQueryCache->add(selectorString, *this, ec);
 }
 
 MediaQueryMatcher& Document::mediaQueryMatcher()

Modified: trunk/Source/WebCore/dom/Document.h (164853 => 164854)


--- trunk/Source/WebCore/dom/Document.h	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/Document.h	2014-02-28 05:54:09 UTC (rev 164854)
@@ -137,6 +137,7 @@
 class ScriptElementData;
 class ScriptRunner;
 class SecurityOrigin;
+class SelectorQuery;
 class SelectorQueryCache;
 class SerializedScriptValue;
 class SegmentedString;
@@ -306,7 +307,7 @@
     void removeImageElementByLowercasedUsemap(const AtomicStringImpl&, HTMLImageElement&);
     HTMLImageElement* imageElementByLowercasedUsemap(const AtomicStringImpl&) const;
 
-    SelectorQueryCache& selectorQueryCache();
+    SelectorQuery* selectorQueryForString(const String&, ExceptionCode&);
 
     // DOM methods & attributes for Document
 

Modified: trunk/Source/WebCore/dom/Element.cpp (164853 => 164854)


--- trunk/Source/WebCore/dom/Element.cpp	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/Element.cpp	2014-02-28 05:54:09 UTC (rev 164854)
@@ -2365,12 +2365,7 @@
 
 bool Element::webkitMatchesSelector(const String& selector, ExceptionCode& ec)
 {
-    if (selector.isEmpty()) {
-        ec = SYNTAX_ERR;
-        return false;
-    }
-
-    SelectorQuery* selectorQuery = document().selectorQueryCache().add(selector, document(), ec);
+    SelectorQuery* selectorQuery = document().selectorQueryForString(selector, ec);
     return selectorQuery && selectorQuery->matches(*this);
 }
 

Modified: trunk/Source/WebCore/dom/SelectorQuery.cpp (164853 => 164854)


--- trunk/Source/WebCore/dom/SelectorQuery.cpp	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/SelectorQuery.cpp	2014-02-28 05:54:09 UTC (rev 164854)
@@ -333,7 +333,7 @@
     m_selectors.initialize(m_selectorList);
 }
 
-SelectorQuery* SelectorQueryCache::add(const AtomicString& selectors, Document& document, ExceptionCode& ec)
+SelectorQuery* SelectorQueryCache::add(const String& selectors, Document& document, ExceptionCode& ec)
 {
     auto it = m_entries.find(selectors);
     if (it != m_entries.end())

Modified: trunk/Source/WebCore/dom/SelectorQuery.h (164853 => 164854)


--- trunk/Source/WebCore/dom/SelectorQuery.h	2014-02-28 05:53:29 UTC (rev 164853)
+++ trunk/Source/WebCore/dom/SelectorQuery.h	2014-02-28 05:54:09 UTC (rev 164854)
@@ -98,11 +98,11 @@
     WTF_MAKE_FAST_ALLOCATED;
 
 public:
-    SelectorQuery* add(const AtomicString&, Document&, ExceptionCode&);
+    SelectorQuery* add(const String&, Document&, ExceptionCode&);
     void invalidate();
 
 private:
-    HashMap<AtomicString, std::unique_ptr<SelectorQuery>> m_entries;
+    HashMap<String, std::unique_ptr<SelectorQuery>> m_entries;
 };
 
 inline bool SelectorQuery::matches(Element& element) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to