Title: [135534] trunk/Source/WebCore
Revision
135534
Author
[email protected]
Date
2012-11-22 12:06:27 -0800 (Thu, 22 Nov 2012)

Log Message

Get rid of HTMLCollectionCacheBase
https://bugs.webkit.org/show_bug.cgi?id=103085

Reviewed by Sam Weinig.

Merged HTMLCollectionCacheBase into HTMLCollection now that DynamicNodeList and HTMLCollection
share one implementation.

* dom/DynamicNodeList.cpp:
(WebCore::DynamicNodeListCacheBase::rootNode): Merged ownerNodeHasItemRefAttribute since this was
the only caller of this function, and the function name didn't match what it was checking.
(WebCore::DynamicNodeListCacheBase::invalidateCache):
(WebCore::DynamicNodeListCacheBase::invalidateIdNameCacheMaps):
* dom/DynamicNodeList.h:
(WebCore):
(WebCore::DynamicNodeListCacheBase::cachedItemOffset):
(DynamicNodeListCacheBase):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::DynamicNodeListCacheBase::setItemCache):
(WebCore::DynamicNodeListCacheBase::itemBeforeOrAfterCachedItem): Merged cachedElementsArrayOffset()
now that this is the only caller.
(WebCore::HTMLCollection::append):
* html/HTMLCollection.h:
(HTMLCollection):
(WebCore::HTMLCollection::idCache): Moved from HTMLCollectionCacheBase.
(WebCore::HTMLCollection::nameCache): Ditto.
(WebCore::HTMLCollection::appendIdCache): Ditto.
(WebCore::HTMLCollection::appendNameCache): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135533 => 135534)


--- trunk/Source/WebCore/ChangeLog	2012-11-22 19:30:38 UTC (rev 135533)
+++ trunk/Source/WebCore/ChangeLog	2012-11-22 20:06:27 UTC (rev 135534)
@@ -1,3 +1,35 @@
+2012-11-22  Ryosuke Niwa  <[email protected]>
+
+        Get rid of HTMLCollectionCacheBase
+        https://bugs.webkit.org/show_bug.cgi?id=103085
+
+        Reviewed by Sam Weinig.
+
+        Merged HTMLCollectionCacheBase into HTMLCollection now that DynamicNodeList and HTMLCollection
+        share one implementation.
+
+        * dom/DynamicNodeList.cpp:
+        (WebCore::DynamicNodeListCacheBase::rootNode): Merged ownerNodeHasItemRefAttribute since this was
+        the only caller of this function, and the function name didn't match what it was checking.
+        (WebCore::DynamicNodeListCacheBase::invalidateCache):
+        (WebCore::DynamicNodeListCacheBase::invalidateIdNameCacheMaps):
+        * dom/DynamicNodeList.h:
+        (WebCore):
+        (WebCore::DynamicNodeListCacheBase::cachedItemOffset):
+        (DynamicNodeListCacheBase):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::HTMLCollection):
+        (WebCore::DynamicNodeListCacheBase::setItemCache):
+        (WebCore::DynamicNodeListCacheBase::itemBeforeOrAfterCachedItem): Merged cachedElementsArrayOffset()
+        now that this is the only caller.
+        (WebCore::HTMLCollection::append):
+        * html/HTMLCollection.h:
+        (HTMLCollection):
+        (WebCore::HTMLCollection::idCache): Moved from HTMLCollectionCacheBase.
+        (WebCore::HTMLCollection::nameCache): Ditto.
+        (WebCore::HTMLCollection::appendIdCache): Ditto.
+        (WebCore::HTMLCollection::appendNameCache): Ditto.
+
 2012-11-22  Antti Koivisto  <[email protected]>
 
         Merge EditingText into Text

Modified: trunk/Source/WebCore/dom/DynamicNodeList.cpp (135533 => 135534)


--- trunk/Source/WebCore/dom/DynamicNodeList.cpp	2012-11-22 19:30:38 UTC (rev 135533)
+++ trunk/Source/WebCore/dom/DynamicNodeList.cpp	2012-11-22 20:06:27 UTC (rev 135534)
@@ -37,7 +37,8 @@
     if (isRootedAtDocument() && m_ownerNode->inDocument())
         return m_ownerNode->document();
 
-    if (ownerNodeHasItemRefAttribute()) {
+#if ENABLE(MICRODATA)
+    if (m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr && toElement(ownerNode())->fastHasAttribute(HTMLNames::itemrefAttr)) {
         if (m_ownerNode->inDocument())
             return m_ownerNode->document();
 
@@ -46,6 +47,7 @@
             root = parent;
         return root;
     }
+#endif
 
     return m_ownerNode.get();
 }
@@ -60,7 +62,7 @@
     if (isNodeList(type()))
         return;
 
-    const HTMLCollectionCacheBase* cacheBase = static_cast<const HTMLCollectionCacheBase*>(this);
+    const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this);
     cacheBase->m_idCache.clear();
     cacheBase->m_nameCache.clear();
     cacheBase->m_cachedElementsArrayOffset = 0;
@@ -75,7 +77,7 @@
 void DynamicNodeListCacheBase::invalidateIdNameCacheMaps() const
 {
     ASSERT(hasIdNameCache());
-    const HTMLCollectionCacheBase* cacheBase = static_cast<const HTMLCollectionCacheBase*>(this);
+    const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this);
     cacheBase->m_idCache.clear();
     cacheBase->m_nameCache.clear();
 }

Modified: trunk/Source/WebCore/dom/DynamicNodeList.h (135533 => 135534)


--- trunk/Source/WebCore/dom/DynamicNodeList.h	2012-11-22 19:30:38 UTC (rev 135533)
+++ trunk/Source/WebCore/dom/DynamicNodeList.h	2012-11-22 20:06:27 UTC (rev 135534)
@@ -26,7 +26,6 @@
 
 #include "CollectionType.h"
 #include "Document.h"
-#include "Element.h"
 #include "HTMLNames.h"
 #include "NodeList.h"
 #include <wtf/Forward.h>
@@ -34,6 +33,8 @@
 
 namespace WebCore {
 
+class Element;
+
 enum NodeListRootType {
     NodeListIsRootedAtNode,
     NodeListIsRootedAtDocument,
@@ -97,7 +98,6 @@
     ALWAYS_INLINE bool isItemCacheValid() const { return m_isItemCacheValid; }
     ALWAYS_INLINE Node* cachedItem() const { return m_cachedItem; }
     ALWAYS_INLINE unsigned cachedItemOffset() const { return m_cachedItemOffset; }
-    unsigned cachedElementsArrayOffset() const;
 
     ALWAYS_INLINE bool isLengthCacheValid() const { return m_isLengthCacheValid; }
     ALWAYS_INLINE unsigned cachedLength() const { return m_cachedLength; }
@@ -135,7 +135,6 @@
     template <bool forward> Node* iterateForNextNode(Node* current) const;
     template<bool forward> Node* itemBeforeOrAfter(Node* previousItem) const;    
     Node* itemBefore(Node* previousItem) const;
-    bool ownerNodeHasItemRefAttribute() const;
 
     RefPtr<Node> m_ownerNode;
     mutable Node* m_cachedItem;
@@ -183,16 +182,6 @@
     return false;
 }
 
-ALWAYS_INLINE bool DynamicNodeListCacheBase::ownerNodeHasItemRefAttribute() const
-{
-#if ENABLE(MICRODATA)
-    if (m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr)
-        return toElement(ownerNode())->fastHasAttribute(HTMLNames::itemrefAttr);
-#endif
-
-    return false;
-}
-
 class DynamicNodeList : public NodeList, public DynamicNodeListCacheBase {
 public:
     DynamicNodeList(PassRefPtr<Node> ownerNode, CollectionType collectionType, NodeListRootType rootType, NodeListInvalidationType invalidationType)

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (135533 => 135534)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2012-11-22 19:30:38 UTC (rev 135533)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2012-11-22 20:06:27 UTC (rev 135534)
@@ -176,7 +176,7 @@
     
 
 HTMLCollection::HTMLCollection(Node* ownerNode, CollectionType type, ItemAfterOverrideType itemAfterOverrideType)
-    : HTMLCollectionCacheBase(ownerNode, rootTypeFromCollectionType(type), invalidationTypeExcludingIdAndNameAttributes(type),
+    : DynamicNodeListCacheBase(ownerNode, rootTypeFromCollectionType(type), invalidationTypeExcludingIdAndNameAttributes(type),
         WebCore::shouldOnlyIncludeDirectChildren(type), type, itemAfterOverrideType)
 {
     document()->registerNodeListCache(this);
@@ -364,16 +364,11 @@
     setItemCache(item, offset);
     if (overridesItemAfter()) {
         ASSERT(item->isElementNode());
-        static_cast<const HTMLCollectionCacheBase*>(this)->m_cachedElementsArrayOffset = elementsArrayOffset;
+        static_cast<const HTMLCollection*>(this)->m_cachedElementsArrayOffset = elementsArrayOffset;
     } else
         ASSERT(!elementsArrayOffset);
 }
 
-ALWAYS_INLINE unsigned DynamicNodeListCacheBase::cachedElementsArrayOffset() const
-{
-    return overridesItemAfter() ? static_cast<const HTMLCollectionCacheBase*>(this)->m_cachedElementsArrayOffset : 0;
-}
-
 unsigned DynamicNodeListCacheBase::lengthCommon() const
 {
     if (isLengthCacheValid())
@@ -441,7 +436,7 @@
         return 0;
     }
 
-    unsigned offsetInArray = cachedElementsArrayOffset();
+    unsigned offsetInArray = overridesItemAfter() ? static_cast<const HTMLCollection*>(this)->m_cachedElementsArrayOffset : 0;
     while ((currentItem = itemAfter(offsetInArray, currentItem))) {
         currentOffset++;
         if (currentOffset == offset) {
@@ -584,7 +579,7 @@
     return ownerNode()->getElementsByTagName(name);
 }
 
-void HTMLCollectionCacheBase::append(NodeCacheMap& map, const AtomicString& key, Element* element)
+void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
 {
     OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->value;
     if (!vector)

Modified: trunk/Source/WebCore/html/HTMLCollection.h (135533 => 135534)


--- trunk/Source/WebCore/html/HTMLCollection.h	2012-11-22 19:30:38 UTC (rev 135533)
+++ trunk/Source/WebCore/html/HTMLCollection.h	2012-11-22 20:06:27 UTC (rev 135534)
@@ -33,40 +33,8 @@
 
 namespace WebCore {
 
-class Document;
-class Element;
-class Node;
-class NodeList;
-
-class HTMLCollectionCacheBase : public DynamicNodeListCacheBase {
+class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection>, public DynamicNodeListCacheBase {
 public:
-    HTMLCollectionCacheBase(Node* ownerNode, NodeListRootType rootType, NodeListInvalidationType invalidationType,
-        bool shouldOnlyIncludeDirectChildren, CollectionType collectionType, ItemAfterOverrideType itemAfterOverrideType)
-        : DynamicNodeListCacheBase(ownerNode, rootType, invalidationType, shouldOnlyIncludeDirectChildren, collectionType, itemAfterOverrideType)
-    {
-    }
-
-protected:
-    typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
-    Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache.get(name.impl()); }
-    Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameCache.get(name.impl()); }
-    void appendIdCache(const AtomicString& name, Element* element) const { append(m_idCache, name, element); }
-    void appendNameCache(const AtomicString& name, Element* element) const { append(m_nameCache, name, element); }
-
-    static void append(NodeCacheMap&, const AtomicString&, Element*);
-
-private:
-    using DynamicNodeListCacheBase::isRootedAtDocument;
-
-    mutable NodeCacheMap m_idCache;
-    mutable NodeCacheMap m_nameCache;
-    mutable unsigned m_cachedElementsArrayOffset;
-
-    friend class DynamicNodeListCacheBase;
-};
-
-class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection>, public HTMLCollectionCacheBase {
-public:
     static PassRefPtr<HTMLCollection> create(Node* base, CollectionType);
     virtual ~HTMLCollection();
 
@@ -104,8 +72,22 @@
 
     virtual void updateNameCache() const;
 
+    typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
+    Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache.get(name.impl()); }
+    Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameCache.get(name.impl()); }
+    void appendIdCache(const AtomicString& name, Element* element) const { append(m_idCache, name, element); }
+    void appendNameCache(const AtomicString& name, Element* element) const { append(m_nameCache, name, element); }
+
 private:
     bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) const;
+
+    static void append(NodeCacheMap&, const AtomicString&, Element*);
+
+    mutable NodeCacheMap m_idCache;
+    mutable NodeCacheMap m_nameCache;
+    mutable unsigned m_cachedElementsArrayOffset;
+
+    friend DynamicNodeListCacheBase;
 };
 
 } // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to