Merge CollectionCache into HTMLCollection.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jan 2012 00:37:59 +0000 (00:37 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jan 2012 00:37:59 +0000 (00:37 +0000)
<http://webkit.org/b/75423>

Reviewed by Anders Carlsson.

- Move the members of CollectionCache into HTMLCollection.
- Renamed resetCollectionInfo() to invalidateCacheIfNeeded().
- Removed a bunch of overkill HashMap::checkConsistency() calls.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.xcodeproj/project.pbxproj:
* html/CollectionCache.cpp: Removed.
* html/CollectionCache.h: Removed.

    Remove CollectionCache.

* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::namedItemWithIndex):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::~HTMLCollection):
(WebCore::HTMLCollection::invalidateCacheIfNeeded):
(WebCore::HTMLCollection::length):
(WebCore::HTMLCollection::item):
(WebCore::HTMLCollection::nextItem):
(WebCore::HTMLCollection::namedItem):
(WebCore::HTMLCollection::updateNameCache):
(WebCore::HTMLCollection::hasNamedItem):
(WebCore::HTMLCollection::namedItems):
(WebCore::HTMLCollection::append):
* html/HTMLCollection.h:
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::item):
(WebCore::HTMLFormCollection::getNamedItem):
(WebCore::HTMLFormCollection::nextItem):
(WebCore::HTMLFormCollection::namedItem):
(WebCore::HTMLFormCollection::updateNameCache):

    HTMLCollection's m_info and info() become "struct m_cache" (protected.)

* html/HTMLOptionsCollection.cpp:
* html/HTMLOptionsCollection.h:
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::setRecalcListItems):

    Expose HTMLCollection::invalidateCacheIfNeeded() so we can call it from
    HTMLSelectElement::setRecalcListItems().

* html/HTMLFormCollection.h:

    Remove stale declaration of formCollectionInfo() which no longer exists.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@103888 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/CollectionCache.cpp [deleted file]
Source/WebCore/html/CollectionCache.h [deleted file]
Source/WebCore/html/HTMLAllCollection.cpp
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLFormCollection.cpp
Source/WebCore/html/HTMLFormCollection.h
Source/WebCore/html/HTMLOptionsCollection.cpp
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLSelectElement.cpp

index 09d0cdd..688e0f1 100644 (file)
@@ -703,7 +703,6 @@ SET(WebCore_SOURCES
     html/ButtonInputType.cpp
     html/CheckboxInputType.cpp
     html/ClassList.cpp
-    html/CollectionCache.cpp
     html/ColorInputType.cpp
     html/DOMFormData.cpp
     html/DOMSettableTokenList.cpp
index 24d6796..e2cc1c9 100644 (file)
@@ -1,5 +1,62 @@
 2012-01-01  Andreas Kling  <awesomekling@apple.com>
 
+        Merge CollectionCache into HTMLCollection.
+        <http://webkit.org/b/75423>
+
+        Reviewed by Anders Carlsson.
+
+        - Move the members of CollectionCache into HTMLCollection.
+        - Renamed resetCollectionInfo() to invalidateCacheIfNeeded().
+        - Removed a bunch of overkill HashMap::checkConsistency() calls.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/CollectionCache.cpp: Removed.
+        * html/CollectionCache.h: Removed.
+
+            Remove CollectionCache.
+
+        * html/HTMLAllCollection.cpp:
+        (WebCore::HTMLAllCollection::namedItemWithIndex):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::HTMLCollection):
+        (WebCore::HTMLCollection::~HTMLCollection):
+        (WebCore::HTMLCollection::invalidateCacheIfNeeded):
+        (WebCore::HTMLCollection::length):
+        (WebCore::HTMLCollection::item):
+        (WebCore::HTMLCollection::nextItem):
+        (WebCore::HTMLCollection::namedItem):
+        (WebCore::HTMLCollection::updateNameCache):
+        (WebCore::HTMLCollection::hasNamedItem):
+        (WebCore::HTMLCollection::namedItems):
+        (WebCore::HTMLCollection::append):
+        * html/HTMLCollection.h:
+        * html/HTMLFormCollection.cpp:
+        (WebCore::HTMLFormCollection::item):
+        (WebCore::HTMLFormCollection::getNamedItem):
+        (WebCore::HTMLFormCollection::nextItem):
+        (WebCore::HTMLFormCollection::namedItem):
+        (WebCore::HTMLFormCollection::updateNameCache):
+
+            HTMLCollection's m_info and info() become "struct m_cache" (protected.)
+
+        * html/HTMLOptionsCollection.cpp:
+        * html/HTMLOptionsCollection.h:
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::setRecalcListItems):
+
+            Expose HTMLCollection::invalidateCacheIfNeeded() so we can call it from
+            HTMLSelectElement::setRecalcListItems().
+
+        * html/HTMLFormCollection.h:
+
+            Remove stale declaration of formCollectionInfo() which no longer exists.
+
+2012-01-01  Andreas Kling  <awesomekling@apple.com>
+
         Move the remaining collections to caching on their respective base nodes.
         <http://webkit.org/b/75416>
 
index af0d24b..ead6dad 100644 (file)
@@ -1947,8 +1947,6 @@ webcore_sources += \
        Source/WebCore/html/CheckboxInputType.h \
        Source/WebCore/html/ClassList.cpp \
        Source/WebCore/html/ClassList.h \
-       Source/WebCore/html/CollectionCache.cpp \
-       Source/WebCore/html/CollectionCache.h \
        Source/WebCore/html/CollectionType.h \
        Source/WebCore/html/ColorInputType.cpp \
        Source/WebCore/html/ColorInputType.h \
index 6dd1748..0402992 100644 (file)
@@ -691,7 +691,6 @@ SOURCES += \
     html/ButtonInputType.cpp \
     html/CheckboxInputType.cpp \
     html/ClassList.cpp \
-    html/CollectionCache.cpp \
     html/ColorInputType.cpp \
     html/DOMFormData.cpp \
     html/DOMSettableTokenList.cpp \
@@ -1767,7 +1766,6 @@ HEADERS += \
     html/canvas/CanvasStyle.h \
     html/canvas/DataView.h \
     html/ClassList.h \
-    html/CollectionCache.h \
     html/DOMFormData.h \
     html/DOMSettableTokenList.h \
     html/DOMTokenList.h \
index 6efd036..8305fce 100644 (file)
             'dom/ViewportArguments.h',
         ],
         'webcore_html_privateheader_files': [
-            'html/CollectionCache.h',
             'html/CollectionType.h',
             'html/FormAssociatedElement.h',
             'html/HTMLAppletElement.h',
             'html/CheckboxInputType.h',
             'html/ClassList.cpp',
             'html/ClassList.h',
-            'html/CollectionCache.cpp',
             'html/ColorInputType.cpp',
             'html/ColorInputType.h',
             'html/DOMFormData.cpp',
index 4b6ee63..ad88f04 100644 (file)
                93C09A7F0B064EEF005ABD4D /* EventHandlerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93C09A7E0B064EEF005ABD4D /* EventHandlerMac.mm */; };
                93C09A810B064F00005ABD4D /* EventHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93C09A800B064F00005ABD4D /* EventHandler.cpp */; };
                93C09C860B0657AA005ABD4D /* ScrollTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C09C850B0657AA005ABD4D /* ScrollTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               93C441EF0F813A1A00C1A634 /* CollectionCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93C441ED0F813A1A00C1A634 /* CollectionCache.cpp */; };
-               93C441F00F813A1A00C1A634 /* CollectionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C441EE0F813A1A00C1A634 /* CollectionCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93C442000F813AE100C1A634 /* CollectionType.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C441FF0F813AE100C1A634 /* CollectionType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93C4F6EB1108F9A50099D0DB /* AccessibilityScrollbar.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C4F6E91108F9A50099D0DB /* AccessibilityScrollbar.h */; };
                93C841F809CE855C00DFF5E5 /* DOMImplementationFront.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C841F709CE855C00DFF5E5 /* DOMImplementationFront.h */; };
                93C09A7E0B064EEF005ABD4D /* EventHandlerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EventHandlerMac.mm; sourceTree = "<group>"; };
                93C09A800B064F00005ABD4D /* EventHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventHandler.cpp; sourceTree = "<group>"; };
                93C09C850B0657AA005ABD4D /* ScrollTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollTypes.h; sourceTree = "<group>"; };
-               93C441ED0F813A1A00C1A634 /* CollectionCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollectionCache.cpp; sourceTree = "<group>"; };
-               93C441EE0F813A1A00C1A634 /* CollectionCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionCache.h; sourceTree = "<group>"; };
                93C441FF0F813AE100C1A634 /* CollectionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionType.h; sourceTree = "<group>"; };
                93C4F6E91108F9A50099D0DB /* AccessibilityScrollbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityScrollbar.h; sourceTree = "<group>"; };
                93C841F709CE855C00DFF5E5 /* DOMImplementationFront.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMImplementationFront.h; sourceTree = "<group>"; };
                                F55B3D7E1251F12D003EF269 /* CheckboxInputType.h */,
                                4ACBC0BC12713CBD0094F9B2 /* ClassList.cpp */,
                                4ACBC0BD12713CBD0094F9B2 /* ClassList.h */,
-                               93C441ED0F813A1A00C1A634 /* CollectionCache.cpp */,
-                               93C441EE0F813A1A00C1A634 /* CollectionCache.h */,
                                93C441FF0F813AE100C1A634 /* CollectionType.h */,
                                F55B3D7F1251F12D003EF269 /* ColorInputType.cpp */,
                                F55B3D801251F12D003EF269 /* ColorInputType.h */,
                                51FB54F5113E364200821176 /* CloseEvent.h in Headers */,
                                C0C054CB1118C8E400CE2636 /* CodeGenerator.pm in Headers */,
                                BC5EB5DF0E81B9AB00B25965 /* CollapsedBorderValue.h in Headers */,
-                               93C441F00F813A1A00C1A634 /* CollectionCache.h in Headers */,
                                93C442000F813AE100C1A634 /* CollectionType.h in Headers */,
                                B27535670B053814002CE64F /* Color.h in Headers */,
                                C330A22313EC196B0000B45B /* ColorChooser.h in Headers */,
                                A784941B0B5FE507001E237A /* Clipboard.cpp in Sources */,
                                85031B3F0A44EFC700F992E0 /* ClipboardEvent.cpp in Sources */,
                                93F19AFF08245E59001E9ABC /* ClipboardMac.mm in Sources */,
-                               93C441EF0F813A1A00C1A634 /* CollectionCache.cpp in Sources */,
                                B27535660B053814002CE64F /* Color.cpp in Sources */,
                                0FCF33240F2B9715004B6795 /* ColorCG.cpp in Sources */,
                                1ABA76C911D20E47004C201C /* ColorData.cpp in Sources */,
diff --git a/Source/WebCore/html/CollectionCache.cpp b/Source/WebCore/html/CollectionCache.cpp
deleted file mode 100644 (file)
index 07dc76c..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-#include "CollectionCache.h"
-
-#include <wtf/PassOwnPtr.h>
-#include <wtf/text/AtomicString.h>
-
-namespace WebCore {
-
-CollectionCache::CollectionCache()
-    : version(0)
-{
-    reset();
-}
-
-void CollectionCache::reset()
-{
-    current = 0;
-    position = 0;
-    length = 0;
-    hasLength = false;
-    elementsArrayPosition = 0;
-    idCache.clear();
-    nameCache.clear();
-    hasNameCache = false;
-}
-
-#if !ASSERT_DISABLED
-void CollectionCache::checkConsistency()
-{
-    idCache.checkConsistency();
-    nameCache.checkConsistency();
-}
-#endif
-
-void append(CollectionCache::NodeCacheMap& map, const AtomicString& key, Element* element)
-{
-    OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).first->second;
-    if (!vector)
-        vector = adoptPtr(new Vector<Element*>);
-    vector->append(element);
-}
-
-} // namespace WebCore
diff --git a/Source/WebCore/html/CollectionCache.h b/Source/WebCore/html/CollectionCache.h
deleted file mode 100644 (file)
index 2fddb55..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef CollectionCache_h
-#define CollectionCache_h
-
-#include <wtf/Forward.h>
-#include <wtf/HashMap.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-class Element;
-
-struct CollectionCache {
-    WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(CollectionCache);
-public:
-    CollectionCache();
-
-    void reset();
-
-    void checkConsistency();
-
-    typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
-
-    uint64_t version;
-    Element* current;
-    unsigned position;
-    unsigned length;
-    int elementsArrayPosition;
-    NodeCacheMap idCache;
-    NodeCacheMap nameCache;
-    bool hasLength;
-    bool hasNameCache;
-};
-
-void append(CollectionCache::NodeCacheMap&, const AtomicString&, Element*);
-    
-#if ASSERT_DISABLED
-inline void CollectionCache::checkConsistency() { }
-#endif
-
-} // namespace
-
-#endif
index cc9ed1d..3dc07a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "HTMLAllCollection.h"
 
-#include "CollectionCache.h"
 #include "Element.h"
 
 namespace WebCore {
@@ -50,17 +49,16 @@ Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned i
     if (!base())
         return 0;
 
-    resetCollectionInfo();
+    invalidateCacheIfNeeded();
     updateNameCache();
-    info()->checkConsistency();
 
-    if (Vector<Element*>* idCache = info()->idCache.get(name.impl())) {
+    if (Vector<Element*>* idCache = m_cache.idCache.get(name.impl())) {
         if (index < idCache->size())
             return idCache->at(index);
         index -= idCache->size();
     }
 
-    if (Vector<Element*>* nameCache = info()->nameCache.get(name.impl())) {
+    if (Vector<Element*>* nameCache = m_cache.nameCache.get(name.impl())) {
         if (index < nameCache->size())
             return nameCache->at(index);
     }
index 0d3f8f2..6a65550 100644 (file)
@@ -23,7 +23,6 @@
 #include "config.h"
 #include "HTMLCollection.h"
 
-#include "CollectionCache.h"
 #include "HTMLDocument.h"
 #include "HTMLElement.h"
 #include "HTMLNames.h"
@@ -39,10 +38,8 @@ using namespace HTMLNames;
 
 HTMLCollection::HTMLCollection(Node* base, CollectionType type)
     : m_includeChildren(shouldIncludeChildren(type))
-    , m_ownsInfo(false)
     , m_type(type)
     , m_base(base)
-    , m_info(0)
 {
 }
 
@@ -85,8 +82,6 @@ PassRefPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType typ
 
 HTMLCollection::~HTMLCollection()
 {
-    if (m_ownsInfo)
-        delete m_info;
 }
 
 void HTMLCollection::detachFromNode()
@@ -94,23 +89,24 @@ void HTMLCollection::detachFromNode()
     m_base = 0;
 }
 
-void HTMLCollection::resetCollectionInfo() const
+void HTMLCollection::invalidateCacheIfNeeded() const
 {
     ASSERT(m_base);
 
     uint64_t docversion = static_cast<HTMLDocument*>(m_base->document())->domTreeVersion();
 
-    if (!m_info) {
-        m_info = new CollectionCache;
-        m_ownsInfo = true;
-        m_info->version = docversion;
+    if (m_cache.version == docversion)
         return;
-    }
 
-    if (m_info->version != docversion) {
-        m_info->reset();
-        m_info->version = docversion;
-    }
+    m_cache.current = 0;
+    m_cache.position = 0;
+    m_cache.length = 0;
+    m_cache.hasLength = false;
+    m_cache.elementsArrayPosition = 0;
+    m_cache.idCache.clear();
+    m_cache.nameCache.clear();
+    m_cache.hasNameCache = false;
+    m_cache.version = docversion;
 }
 
 inline bool HTMLCollection::isAcceptableElement(Element* element) const
@@ -207,12 +203,12 @@ unsigned HTMLCollection::length() const
     if (!m_base)
         return 0;
 
-    resetCollectionInfo();
-    if (!m_info->hasLength) {
-        m_info->length = calcLength();
-        m_info->hasLength = true;
+    invalidateCacheIfNeeded();
+    if (!m_cache.hasLength) {
+        m_cache.length = calcLength();
+        m_cache.hasLength = true;
     }
-    return m_info->length;
+    return m_cache.length;
 }
 
 Node* HTMLCollection::item(unsigned index) const
@@ -220,23 +216,23 @@ Node* HTMLCollection::item(unsigned index) const
     if (!m_base)
         return 0;
 
-     resetCollectionInfo();
-     if (m_info->current && m_info->position == index)
-         return m_info->current;
-     if (m_info->hasLength && m_info->length <= index)
+     invalidateCacheIfNeeded();
+     if (m_cache.current && m_cache.position == index)
+         return m_cache.current;
+     if (m_cache.hasLength && m_cache.length <= index)
          return 0;
-     if (!m_info->current || m_info->position > index) {
-         m_info->current = itemAfter(0);
-         m_info->position = 0;
-         if (!m_info->current)
+     if (!m_cache.current || m_cache.position > index) {
+         m_cache.current = itemAfter(0);
+         m_cache.position = 0;
+         if (!m_cache.current)
              return 0;
      }
-     Element* e = m_info->current;
-     for (unsigned pos = m_info->position; e && pos < index; pos++)
+     Element* e = m_cache.current;
+     for (unsigned pos = m_cache.position; e && pos < index; pos++)
          e = itemAfter(e);
-     m_info->current = e;
-     m_info->position = index;
-     return m_info->current;
+     m_cache.current = e;
+     m_cache.position = index;
+     return m_cache.current;
 }
 
 Node* HTMLCollection::firstItem() const
@@ -247,12 +243,12 @@ Node* HTMLCollection::firstItem() const
 Node* HTMLCollection::nextItem() const
 {
      ASSERT(m_base);
-     resetCollectionInfo();
+     invalidateCacheIfNeeded();
 
      // Look for the 'second' item. The first one is currentItem, already given back.
-     Element* retval = itemAfter(m_info->current);
-     m_info->current = retval;
-     m_info->position++;
+     Element* retval = itemAfter(m_cache.current);
+     m_cache.current = retval;
+     m_cache.position++;
      return retval;
 }
 
@@ -294,23 +290,23 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
     // attribute. If a match is not found, the method then searches for an
     // object with a matching name attribute, but only on those elements
     // that are allowed a name attribute.
-    resetCollectionInfo();
+    invalidateCacheIfNeeded();
 
     for (Element* e = itemAfter(0); e; e = itemAfter(e)) {
         if (checkForNameMatch(e, /* checkName */ false, name)) {
-            m_info->current = e;
+            m_cache.current = e;
             return e;
         }
     }
 
     for (Element* e = itemAfter(0); e; e = itemAfter(e)) {
         if (checkForNameMatch(e, /* checkName */ true, name)) {
-            m_info->current = e;
+            m_cache.current = e;
             return e;
         }
     }
 
-    m_info->current = 0;
+    m_cache.current = 0;
     return 0;
 }
 
@@ -318,7 +314,7 @@ void HTMLCollection::updateNameCache() const
 {
     ASSERT(m_base);
 
-    if (m_info->hasNameCache)
+    if (m_cache.hasNameCache)
         return;
 
     for (Element* element = itemAfter(0); element; element = itemAfter(element)) {
@@ -328,12 +324,12 @@ void HTMLCollection::updateNameCache() const
         const AtomicString& idAttrVal = e->getIdAttribute();
         const AtomicString& nameAttrVal = e->getAttribute(nameAttr);
         if (!idAttrVal.isEmpty())
-            append(m_info->idCache, idAttrVal, e);
+            append(m_cache.idCache, idAttrVal, e);
         if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (m_type != DocAll || nameShouldBeVisibleInDocumentAll(e)))
-            append(m_info->nameCache, nameAttrVal, e);
+            append(m_cache.nameCache, nameAttrVal, e);
     }
 
-    m_info->hasNameCache = true;
+    m_cache.hasNameCache = true;
 }
 
 bool HTMLCollection::hasNamedItem(const AtomicString& name) const
@@ -344,16 +340,15 @@ bool HTMLCollection::hasNamedItem(const AtomicString& name) const
     if (name.isEmpty())
         return false;
 
-    resetCollectionInfo();
+    invalidateCacheIfNeeded();
     updateNameCache();
-    m_info->checkConsistency();
 
-    if (Vector<Element*>* idCache = m_info->idCache.get(name.impl())) {
+    if (Vector<Element*>* idCache = m_cache.idCache.get(name.impl())) {
         if (!idCache->isEmpty())
             return true;
     }
 
-    if (Vector<Element*>* nameCache = m_info->nameCache.get(name.impl())) {
+    if (Vector<Element*>* nameCache = m_cache.nameCache.get(name.impl())) {
         if (!nameCache->isEmpty())
             return true;
     }
@@ -370,13 +365,12 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Node> >&
     if (name.isEmpty())
         return;
 
-    resetCollectionInfo();
+    invalidateCacheIfNeeded();
     updateNameCache();
-    m_info->checkConsistency();
 
-    Vector<Element*>* idResults = m_info->idCache.get(name.impl());
-    Vector<Element*>* nameResults = m_info->nameCache.get(name.impl());
-    
+    Vector<Element*>* idResults = m_cache.idCache.get(name.impl());
+    Vector<Element*>* nameResults = m_cache.nameCache.get(name.impl());
+
     for (unsigned i = 0; idResults && i < idResults->size(); ++i)
         result.append(idResults->at(i));
 
@@ -392,4 +386,12 @@ PassRefPtr<NodeList> HTMLCollection::tags(const String& name)
     return m_base->getElementsByTagName(name);
 }
 
+void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
+{
+    OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).first->second;
+    if (!vector)
+        vector = adoptPtr(new Vector<Element*>);
+    vector->append(element);
+}
+
 } // namespace WebCore
index 1bca3d3..267c268 100644 (file)
@@ -36,8 +36,6 @@ class Element;
 class Node;
 class NodeList;
 
-struct CollectionCache;
-
 class HTMLCollection : public RefCounted<HTMLCollection> {
 public:
     static PassRefPtr<HTMLCollection> create(Node* base, CollectionType);
@@ -65,12 +63,26 @@ public:
 protected:
     HTMLCollection(Node* base, CollectionType);
 
-    CollectionCache* info() const { return m_info; }
-    void resetCollectionInfo() const;
+    void invalidateCacheIfNeeded() const;
 
     virtual void updateNameCache() const;
     virtual Element* itemAfter(Element*) const;
 
+    typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
+    static void append(NodeCacheMap&, const AtomicString&, Element*);
+
+    mutable struct {
+        NodeCacheMap idCache;
+        NodeCacheMap nameCache;
+        uint64_t version;
+        Element* current;
+        unsigned position;
+        unsigned length;
+        int elementsArrayPosition;
+        bool hasLength;
+        bool hasNameCache;
+    } m_cache;
+
 private:
     static bool shouldIncludeChildren(CollectionType);
     bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) const;
@@ -80,12 +92,9 @@ private:
     bool isAcceptableElement(Element*) const;
 
     bool m_includeChildren : 1;
-    mutable bool m_ownsInfo : 1;
     unsigned m_type : 5; // CollectionType
 
     Node* m_base;
-
-    mutable CollectionCache* m_info;
 };
 
 } // namespace
index db63693..6b19d44 100644 (file)
@@ -23,7 +23,6 @@
 #include "config.h"
 #include "HTMLFormCollection.h"
 
-#include "CollectionCache.h"
 #include "HTMLFormControlElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLImageElement.h"
@@ -61,30 +60,30 @@ Node* HTMLFormCollection::item(unsigned index) const
     if (!base())
         return 0;
 
-    resetCollectionInfo();
+    invalidateCacheIfNeeded();
 
-    if (info()->current && info()->position == index)
-        return info()->current;
+    if (m_cache.current && m_cache.position == index)
+        return m_cache.current;
 
-    if (info()->hasLength && info()->length <= index)
+    if (m_cache.hasLength && m_cache.length <= index)
         return 0;
 
-    if (!info()->current || info()->position > index) {
-        info()->current = 0;
-        info()->position = 0;
-        info()->elementsArrayPosition = 0;
+    if (!m_cache.current || m_cache.position > index) {
+        m_cache.current = 0;
+        m_cache.position = 0;
+        m_cache.elementsArrayPosition = 0;
     }
 
     Vector<FormAssociatedElement*>& elementsArray = static_cast<HTMLFormElement*>(base())->m_associatedElements;
-    unsigned currentIndex = info()->position;
+    unsigned currentIndex = m_cache.position;
     
-    for (unsigned i = info()->elementsArrayPosition; i < elementsArray.size(); i++) {
+    for (unsigned i = m_cache.elementsArrayPosition; i < elementsArray.size(); i++) {
         if (elementsArray[i]->isEnumeratable()) {
             HTMLElement* element = toHTMLElement(elementsArray[i]);
             if (index == currentIndex) {
-                info()->position = index;
-                info()->current = element;
-                info()->elementsArrayPosition = i;
+                m_cache.position = index;
+                m_cache.current = element;
+                m_cache.elementsArrayPosition = i;
                 return element;
             }
 
@@ -100,7 +99,7 @@ Element* HTMLFormCollection::getNamedItem(const QualifiedName& attrName, const A
     if (!base())
         return 0;
 
-    info()->position = 0;
+    m_cache.position = 0;
     return getNamedFormItem(attrName, name, 0);
 }
 
@@ -139,7 +138,7 @@ Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, con
 
 Node* HTMLFormCollection::nextItem() const
 {
-    return item(info()->position + 1);
+    return item(m_cache.position + 1);
 }
 
 Node* HTMLFormCollection::namedItem(const AtomicString& name) const
@@ -152,12 +151,12 @@ Node* HTMLFormCollection::namedItem(const AtomicString& name) const
     // attribute. If a match is not found, the method then searches for an
     // object with a matching name attribute, but only on those elements
     // that are allowed a name attribute.
-    resetCollectionInfo();
-    info()->current = getNamedItem(idAttr, name);
-    if (info()->current)
-        return info()->current;
-    info()->current = getNamedItem(nameAttr, name);
-    return info()->current;
+    invalidateCacheIfNeeded();
+    m_cache.current = getNamedItem(idAttr, name);
+    if (m_cache.current)
+        return m_cache.current;
+    m_cache.current = getNamedItem(nameAttr, name);
+    return m_cache.current;
 }
 
 void HTMLFormCollection::updateNameCache() const
@@ -165,7 +164,7 @@ void HTMLFormCollection::updateNameCache() const
     if (!base())
         return;
 
-    if (info()->hasNameCache)
+    if (m_cache.hasNameCache)
         return;
 
     HashSet<AtomicStringImpl*> foundInputElements;
@@ -179,11 +178,11 @@ void HTMLFormCollection::updateNameCache() const
             const AtomicString& idAttrVal = element->getIdAttribute();
             const AtomicString& nameAttrVal = element->getAttribute(nameAttr);
             if (!idAttrVal.isEmpty()) {
-                append(info()->idCache, idAttrVal, element);
+                append(m_cache.idCache, idAttrVal, element);
                 foundInputElements.add(idAttrVal.impl());
             }
             if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) {
-                append(info()->nameCache, nameAttrVal, element);
+                append(m_cache.nameCache, nameAttrVal, element);
                 foundInputElements.add(nameAttrVal.impl());
             }
         }
@@ -194,12 +193,12 @@ void HTMLFormCollection::updateNameCache() const
         const AtomicString& idAttrVal = element->getIdAttribute();
         const AtomicString& nameAttrVal = element->getAttribute(nameAttr);
         if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl()))
-            append(info()->idCache, idAttrVal, element);
+            append(m_cache.idCache, idAttrVal, element);
         if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl()))
-            append(info()->nameCache, nameAttrVal, element);
+            append(m_cache.nameCache, nameAttrVal, element);
     }
 
-    info()->hasNameCache = true;
+    m_cache.hasNameCache = true;
 }
 
 }
index d9afccf..7d29638 100644 (file)
@@ -50,8 +50,6 @@ private:
     virtual void updateNameCache() const;
     virtual unsigned calcLength() const;
 
-    static CollectionCache* formCollectionInfo(HTMLFormElement*);
-
     Element* getNamedItem(const QualifiedName& attrName, const AtomicString& name) const;
     Element* getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const;
 
index fea385e..3abb353 100644 (file)
@@ -21,7 +21,6 @@
 #include "config.h"
 #include "HTMLOptionsCollection.h"
 
-#include "CollectionCache.h"
 #include "ExceptionCode.h"
 #include "HTMLOptionElement.h"
 #include "HTMLSelectElement.h"
@@ -99,10 +98,4 @@ void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec)
     toHTMLSelectElement(base())->setLength(length, ec);
 }
 
-void HTMLOptionsCollection::invalidateCache()
-{
-    if (info())
-        info()->reset();
-}
-
 } //namespace
index e6a1413..333334b 100644 (file)
@@ -46,7 +46,7 @@ public:
 
     void setLength(unsigned, ExceptionCode&);
 
-    void invalidateCache();
+    using HTMLCollection::invalidateCacheIfNeeded;
 
 private:
     HTMLOptionsCollection(HTMLSelectElement*);
index e9eb71a..95421f3 100644 (file)
@@ -689,7 +689,7 @@ void HTMLSelectElement::setRecalcListItems()
     setOptionsChangedOnRenderer();
     setNeedsStyleRecalc();
     if (!inDocument() && m_optionsCollection)
-        m_optionsCollection->invalidateCache();
+        m_optionsCollection->invalidateCacheIfNeeded();
 }
 
 void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const