[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

rolandsteiner at chromium.org rolandsteiner at chromium.org
Mon Feb 21 00:30:46 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit eecc2145167340daacfc5197b7c0a705db6e8df0
Author: rolandsteiner at chromium.org <rolandsteiner at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Feb 1 10:41:19 2011 +0000

    2011-02-01  Roland Steiner  <rolandsteiner at chromium.org>
    
            Reviewed by Dimitri Glazkov.
    
            Bug 53289 - DOM: Move DocumentOrderedMap from Document into separate files
            https://bugs.webkit.org/show_bug.cgi?id=53289
    
            Moving the nested class DocumentOrderedMap from Document into separate files,
            updating code where necessary.
    
            No new tests. (refactoring)
    
            * Android.mk:
            * CMakeLists.txt:
            * GNUMakefile.am:
            * WebCore.gypi:
            * WebCore.pro:
            * WebCore.vcproj/WebCore.vcproj:
            * WebCore.xcodeproj/project.pbxproj:
            * dom/Document.cpp:
            (WebCore::Document::getElementById):
            (WebCore::Document::getImageMap):
            * dom/Document.h:
            * dom/DocumentOrderedMap.cpp: Added.
            (WebCore::keyMatchesId):
            (WebCore::keyMatchesMapName):
            (WebCore::keyMatchesLowercasedMapName):
            (WebCore::DocumentOrderedMap::clear):
            (WebCore::DocumentOrderedMap::add):
            (WebCore::DocumentOrderedMap::remove):
            (WebCore::DocumentOrderedMap::get):
            (WebCore::DocumentOrderedMap::getElementById):
            (WebCore::DocumentOrderedMap::getElementByMapName):
            (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
            * dom/DocumentOrderedMap.h: Added.
            (WebCore::DocumentOrderedMap::contains):
            (WebCore::DocumentOrderedMap::containsMultiple):
            * dom/DOMAllInOne.cpp:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77239 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk
index 25d7166..1af3d1e 100644
--- a/Source/WebCore/Android.mk
+++ b/Source/WebCore/Android.mk
@@ -121,6 +121,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	dom/DocumentFragment.cpp \
 	dom/DocumentMarkerController.cpp \
 	dom/DocumentParser.cpp \
+	dom/DocumentOrderedMap.cpp \
 	dom/DocumentType.cpp \
 	dom/DynamicNodeList.cpp \
 	dom/EditingText.cpp \
diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt
index 6be3c9d..9ac7fe7 100644
--- a/Source/WebCore/CMakeLists.txt
+++ b/Source/WebCore/CMakeLists.txt
@@ -838,6 +838,7 @@ SET(WebCore_SOURCES
     dom/DocumentMarkerController.cpp
     dom/DocumentFragment.cpp
     dom/DocumentParser.cpp
+    dom/DocumentOrderedMap.cpp
     dom/DocumentType.cpp
     dom/DOMImplementation.cpp
     dom/DOMStringList.cpp
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 4f6af61..b41f26e 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,42 @@
+2011-02-01  Roland Steiner  <rolandsteiner at chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Bug 53289 - DOM: Move DocumentOrderedMap from Document into separate files
+        https://bugs.webkit.org/show_bug.cgi?id=53289
+
+        Moving the nested class DocumentOrderedMap from Document into separate files,
+        updating code where necessary.
+
+        No new tests. (refactoring)
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUMakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Document.cpp:
+        (WebCore::Document::getElementById):
+        (WebCore::Document::getImageMap):
+        * dom/Document.h:
+        * dom/DocumentOrderedMap.cpp: Added.
+        (WebCore::keyMatchesId):
+        (WebCore::keyMatchesMapName):
+        (WebCore::keyMatchesLowercasedMapName):
+        (WebCore::DocumentOrderedMap::clear):
+        (WebCore::DocumentOrderedMap::add):
+        (WebCore::DocumentOrderedMap::remove):
+        (WebCore::DocumentOrderedMap::get):
+        (WebCore::DocumentOrderedMap::getElementById):
+        (WebCore::DocumentOrderedMap::getElementByMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
+        * dom/DocumentOrderedMap.h: Added.
+        (WebCore::DocumentOrderedMap::contains):
+        (WebCore::DocumentOrderedMap::containsMultiple):
+        * dom/DOMAllInOne.cpp:
+
 2011-02-01  Mario Sanchez Prada  <msanchez at igalia.com>
 
         Reviewed by Martin Robinson.
diff --git a/Source/WebCore/GNUmakefile.am b/Source/WebCore/GNUmakefile.am
index 5206581..7f6cc54 100644
--- a/Source/WebCore/GNUmakefile.am
+++ b/Source/WebCore/GNUmakefile.am
@@ -1167,6 +1167,8 @@ webcore_sources += \
 	Source/WebCore/dom/DocumentMarkerController.cpp \
 	Source/WebCore/dom/DocumentMarkerController.h \
 	Source/WebCore/dom/DocumentMarker.h \
+	Source/WebCore/dom/DocumentOrderedMap.cpp \
+	Source/WebCore/dom/DocumentOrderedMap.h \
 	Source/WebCore/dom/DocumentParser.cpp \
 	Source/WebCore/dom/DocumentParser.h \
 	Source/WebCore/dom/DocumentTiming.h \
diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi
index 1f8efd8..48c9ffa 100644
--- a/Source/WebCore/WebCore.gypi
+++ b/Source/WebCore/WebCore.gypi
@@ -1220,6 +1220,8 @@
             'dom/DocumentMarker.h',
             'dom/DocumentMarkerController.cpp',
             'dom/DocumentMarkerController.h',
+            'dom/DocumentOrderedMap.cpp',
+            'dom/DocumentOrderedMap.h',
             'dom/DocumentParser.cpp',
             'dom/DocumentParser.h',
             'dom/DocumentTiming.h',
diff --git a/Source/WebCore/WebCore.pro b/Source/WebCore/WebCore.pro
index 9e458f0..2004242 100644
--- a/Source/WebCore/WebCore.pro
+++ b/Source/WebCore/WebCore.pro
@@ -730,6 +730,7 @@ SOURCES += \
     dom/Document.cpp \
     dom/DocumentFragment.cpp \
     dom/DocumentMarkerController.cpp \
+    dom/DocumentOrderedMap.cpp \
     dom/DocumentParser.cpp \
     dom/DocumentType.cpp \
     dom/DOMImplementation.cpp \
@@ -1664,6 +1665,7 @@ HEADERS += \
     dom/DocumentFragment.h \
     dom/DocumentMarker.h \
     dom/DocumentMarkerController.h \
+    dom/DocumentOrderedMap.h \
     dom/DocumentType.h \
     dom/DOMImplementation.h \
     dom/DOMStringList.h \
diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
index bf8f539..8353a72 100755
--- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -43078,6 +43078,62 @@
 				>
 			</File>
 			<File
+				RelativePath="..\dom\DocumentOrderedMap.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug_Cairo_CFLite|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release_Cairo_CFLite|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug_All|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release_LTCG|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="..\dom\DocumentOrderedMap.h"
+				>
+			</File>
+			<File
 				RelativePath="..\dom\DocumentParser.cpp"
 				>
 				<FileConfiguration
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 415602e..d1d2ad1 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -316,6 +316,8 @@
 		1479FAF4109AE37500DED655 /* RenderRubyText.h in Headers */ = {isa = PBXBuildFile; fileRef = 1479FAEC109AE37500DED655 /* RenderRubyText.h */; };
 		148AFDA50AF58360008CC700 /* ExceptionHandlers.h in Headers */ = {isa = PBXBuildFile; fileRef = 148AFDA30AF58360008CC700 /* ExceptionHandlers.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		148AFDA60AF58360008CC700 /* ExceptionHandlers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 148AFDA40AF58360008CC700 /* ExceptionHandlers.mm */; };
+		14947FFD12F80CD200A0F631 /* DocumentOrderedMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */; };
+		14947FFE12F80CD200A0F631 /* DocumentOrderedMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		14993BE50B2F2B1C0050497F /* FocusController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14993BE30B2F2B1C0050497F /* FocusController.cpp */; };
 		14993BE60B2F2B1C0050497F /* FocusController.h in Headers */ = {isa = PBXBuildFile; fileRef = 14993BE40B2F2B1C0050497F /* FocusController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		14C9A5EA0B3D105F005A0232 /* Settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14C9A5E90B3D105F005A0232 /* Settings.cpp */; };
@@ -6642,6 +6644,8 @@
 		14813BF309EDF88E00F757E1 /* IDLParser.pm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.script.perl; name = IDLParser.pm; path = scripts/IDLParser.pm; sourceTree = "<group>"; };
 		148AFDA30AF58360008CC700 /* ExceptionHandlers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ExceptionHandlers.h; sourceTree = "<group>"; };
 		148AFDA40AF58360008CC700 /* ExceptionHandlers.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ExceptionHandlers.mm; sourceTree = "<group>"; };
+		14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentOrderedMap.cpp; sourceTree = "<group>"; };
+		14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentOrderedMap.h; sourceTree = "<group>"; };
 		14993BE30B2F2B1C0050497F /* FocusController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FocusController.cpp; sourceTree = "<group>"; };
 		14993BE40B2F2B1C0050497F /* FocusController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FocusController.h; sourceTree = "<group>"; };
 		14C9A5E90B3D105F005A0232 /* Settings.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Settings.cpp; sourceTree = "<group>"; };
@@ -18997,6 +19001,8 @@
 				ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */,
 				CE057FA31220731100A476D5 /* DocumentMarkerController.cpp */,
 				CE057FA41220731100A476D5 /* DocumentMarkerController.h */,
+				14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */,
+				14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */,
 				A8C2280D11D4A59700D5A7D3 /* DocumentParser.cpp */,
 				BCCFBAE70B5152ED0001F1D7 /* DocumentParser.h */,
 				86D982F6125C154000AD9E3D /* DocumentTiming.h */,
@@ -22469,6 +22475,7 @@
 				0F3DD45012F5EA1B000D9190 /* ShadowBlur.h in Headers */,
 				BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */,
 				BCE4413612F7490B009B84B8 /* FontWidthVariant.h in Headers */,
+				14947FFE12F80CD200A0F631 /* DocumentOrderedMap.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -25168,6 +25175,7 @@
 				977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
 				0F3DD44F12F5EA1B000D9190 /* ShadowBlur.cpp in Sources */,
 				BCE4413312F748E2009B84B8 /* RenderCombineText.cpp in Sources */,
+				14947FFD12F80CD200A0F631 /* DocumentOrderedMap.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/Source/WebCore/dom/DOMAllInOne.cpp b/Source/WebCore/dom/DOMAllInOne.cpp
index aa85bfb..c88aecf 100644
--- a/Source/WebCore/dom/DOMAllInOne.cpp
+++ b/Source/WebCore/dom/DOMAllInOne.cpp
@@ -60,6 +60,7 @@
 #include "Document.cpp"
 #include "DocumentFragment.cpp"
 #include "DocumentMarkerController.cpp"
+#include "DocumentOrderedMap.cpp"
 #include "DocumentParser.cpp"
 #include "DocumentType.cpp"
 #include "DynamicNodeList.cpp"
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 6ef04be..7f69f51 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -226,11 +226,6 @@ using namespace HTMLNames;
 // for dual G5s. :)
 static const int cLayoutScheduleThreshold = 250;
 
-// These functions can't have internal linkage because they are used as template arguments.
-bool keyMatchesId(AtomicStringImpl*, Element*);
-bool keyMatchesMapName(AtomicStringImpl*, Element*);
-bool keyMatchesLowercasedMapName(AtomicStringImpl*, Element*);
-
 // DOM Level 2 says (letters added):
 //
 // a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.
@@ -507,12 +502,6 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML, con
 #endif
 }
 
-inline void Document::DocumentOrderedMap::clear()
-{
-    m_map.clear();
-    m_duplicateCounts.clear();
-}
-
 void Document::removedLastRef()
 {
     ASSERT(!m_deletionHasBegun);
@@ -995,87 +984,11 @@ PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const
     return createElement(qName, false);
 }
 
-inline void Document::DocumentOrderedMap::add(AtomicStringImpl* key, Element* element)
-{
-    ASSERT(key);
-    ASSERT(element);
-
-    if (!m_duplicateCounts.contains(key)) {
-        // Fast path. The key is not already in m_duplicateCounts, so we assume that it's
-        // also not already in m_map and try to add it. If that add succeeds, we're done.
-        pair<Map::iterator, bool> addResult = m_map.add(key, element);
-        if (addResult.second)
-            return;
-
-        // The add failed, so this key was already cached in m_map.
-        // There are multiple elements with this key. Remove the m_map
-        // cache for this key so get searches for it next time it is called.
-        m_map.remove(addResult.first);
-        m_duplicateCounts.add(key);
-    } else {
-        // There are multiple elements with this key. Remove the m_map
-        // cache for this key so get will search for it next time it is called.
-        Map::iterator cachedItem = m_map.find(key);
-        if (cachedItem != m_map.end()) {
-            m_map.remove(cachedItem);
-            m_duplicateCounts.add(key);
-        }
-    }
-
-    m_duplicateCounts.add(key);
-}
-
-inline void Document::DocumentOrderedMap::remove(AtomicStringImpl* key, Element* element)
-{
-    ASSERT(key);
-    ASSERT(element);
-
-    m_map.checkConsistency();
-    Map::iterator cachedItem = m_map.find(key);
-    if (cachedItem != m_map.end() && cachedItem->second == element)
-        m_map.remove(cachedItem);
-    else
-        m_duplicateCounts.remove(key);
-}
-
-template<bool keyMatches(AtomicStringImpl*, Element*)> inline Element* Document::DocumentOrderedMap::get(AtomicStringImpl* key, const Document* document) const
-{
-    ASSERT(key);
-
-    m_map.checkConsistency();
-
-    Element* element = m_map.get(key);
-    if (element)
-        return element;
-
-    if (m_duplicateCounts.contains(key)) {
-        // We know there's at least one node that matches; iterate to find the first one.
-        for (Node* node = document->firstChild(); node; node = node->traverseNextNode()) {
-            if (!node->isElementNode())
-                continue;
-            element = static_cast<Element*>(node);
-            if (!keyMatches(key, element))
-                continue;
-            m_duplicateCounts.remove(key);
-            m_map.set(key, element);
-            return element;
-        }
-        ASSERT_NOT_REACHED();
-    }
-
-    return 0;
-}
-
-inline bool keyMatchesId(AtomicStringImpl* key, Element* element)
-{
-    return element->hasID() && element->getIdAttribute().impl() == key;
-}
-
 Element* Document::getElementById(const AtomicString& elementId) const
 {
     if (elementId.isEmpty())
         return 0;
-    return m_elementsById.get<keyMatchesId>(elementId.impl(), this);
+    return m_elementsById.getElementById(elementId.impl(), this);
 }
 
 String Document::readyState() const
@@ -3900,16 +3813,6 @@ void Document::removeImageMap(HTMLMapElement* imageMap)
     m_imageMapsByName.remove(name, imageMap);
 }
 
-inline bool keyMatchesMapName(AtomicStringImpl* key, Element* element)
-{
-    return element->hasTagName(mapTag) && static_cast<HTMLMapElement*>(element)->getName().impl() == key;
-}
-
-inline bool keyMatchesLowercasedMapName(AtomicStringImpl* key, Element* element)
-{
-    return element->hasTagName(mapTag) && static_cast<HTMLMapElement*>(element)->getName().lower().impl() == key;
-}
-
 HTMLMapElement* Document::getImageMap(const String& url) const
 {
     if (url.isNull())
@@ -3917,8 +3820,8 @@ HTMLMapElement* Document::getImageMap(const String& url) const
     size_t hashPos = url.find('#');
     String name = (hashPos == notFound ? url : url.substring(hashPos + 1)).impl();
     if (isHTMLDocument())
-        return static_cast<HTMLMapElement*>(m_imageMapsByName.get<keyMatchesLowercasedMapName>(AtomicString(name.lower()).impl(), this));
-    return static_cast<HTMLMapElement*>(m_imageMapsByName.get<keyMatchesMapName>(AtomicString(name).impl(), this));
+        return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
+    return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
 }
 
 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder)
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 04901e1..170822b 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -33,15 +33,16 @@
 #include "Color.h"
 #include "ContainerNode.h"
 #include "DOMTimeStamp.h"
+#include "DocumentOrderedMap.h"
 #include "DocumentTiming.h"
 #include "QualifiedName.h"
 #include "ScriptExecutionContext.h"
 #include "Timer.h"
 #include "ViewportArguments.h"
 #include <wtf/FixedArray.h>
-#include <wtf/HashCountedSet.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
 
 #if USE(JSC)
 #include <runtime/WeakGCMap.h>
@@ -1094,28 +1095,6 @@ protected:
     void clearXMLVersion() { m_xmlVersion = String(); }
 
 private:
-    class DocumentOrderedMap {
-    public:
-        void add(AtomicStringImpl*, Element*);
-        void remove(AtomicStringImpl*, Element*);
-        void clear();
-
-        bool contains(AtomicStringImpl*) const;
-        bool containsMultiple(AtomicStringImpl*) const;
-        template<bool keyMatches(AtomicStringImpl*, Element*)> Element* get(AtomicStringImpl*, const Document*) const;
-
-        void checkConsistency() const;
-
-    private:
-        typedef HashMap<AtomicStringImpl*, Element*> Map;
-
-        // We maintain the invariant that m_duplicateCounts is the count of all elements with a given key
-        // excluding the one referenced in m_map, if any. This means it one less than the total count
-        // when the first node with a given key is cached, otherwise the same as the total count.
-        mutable Map m_map;
-        mutable HashCountedSet<AtomicStringImpl*> m_duplicateCounts;
-    };
-
     friend class IgnoreDestructiveWriteCountIncrementer;
 
     void detachParser();
@@ -1411,16 +1390,6 @@ private:
 #endif
 };
 
-inline bool Document::DocumentOrderedMap::contains(AtomicStringImpl* id) const
-{
-    return m_map.contains(id) || m_duplicateCounts.contains(id);
-}
-
-inline bool Document::DocumentOrderedMap::containsMultiple(AtomicStringImpl* id) const
-{
-    return m_duplicateCounts.contains(id);
-}
-
 inline bool Document::hasElementWithId(AtomicStringImpl* id) const
 {
     ASSERT(id);
diff --git a/Source/WebCore/dom/DocumentOrderedMap.cpp b/Source/WebCore/dom/DocumentOrderedMap.cpp
new file mode 100644
index 0000000..787fcf4
--- /dev/null
+++ b/Source/WebCore/dom/DocumentOrderedMap.cpp
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DocumentOrderedMap.h"
+
+#include "Element.h"
+#include "HTMLMapElement.h"
+#include "HTMLNames.h"
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+inline bool keyMatchesId(AtomicStringImpl* key, Element* element)
+{
+    return element->hasID() && element->getIdAttribute().impl() == key;
+}
+
+inline bool keyMatchesMapName(AtomicStringImpl* key, Element* element)
+{
+    return element->hasTagName(mapTag) && static_cast<HTMLMapElement*>(element)->getName().impl() == key;
+}
+
+inline bool keyMatchesLowercasedMapName(AtomicStringImpl* key, Element* element)
+{
+    return element->hasTagName(mapTag) && static_cast<HTMLMapElement*>(element)->getName().lower().impl() == key;
+}
+
+void DocumentOrderedMap::clear()
+{
+    m_map.clear();
+    m_duplicateCounts.clear();
+}
+
+void DocumentOrderedMap::add(AtomicStringImpl* key, Element* element)
+{
+    ASSERT(key);
+    ASSERT(element);
+
+    if (!m_duplicateCounts.contains(key)) {
+        // Fast path. The key is not already in m_duplicateCounts, so we assume that it's
+        // also not already in m_map and try to add it. If that add succeeds, we're done.
+        pair<Map::iterator, bool> addResult = m_map.add(key, element);
+        if (addResult.second)
+            return;
+
+        // The add failed, so this key was already cached in m_map.
+        // There are multiple elements with this key. Remove the m_map
+        // cache for this key so get searches for it next time it is called.
+        m_map.remove(addResult.first);
+        m_duplicateCounts.add(key);
+    } else {
+        // There are multiple elements with this key. Remove the m_map
+        // cache for this key so get will search for it next time it is called.
+        Map::iterator cachedItem = m_map.find(key);
+        if (cachedItem != m_map.end()) {
+            m_map.remove(cachedItem);
+            m_duplicateCounts.add(key);
+        }
+    }
+
+    m_duplicateCounts.add(key);
+}
+
+void DocumentOrderedMap::remove(AtomicStringImpl* key, Element* element)
+{
+    ASSERT(key);
+    ASSERT(element);
+
+    m_map.checkConsistency();
+    Map::iterator cachedItem = m_map.find(key);
+    if (cachedItem != m_map.end() && cachedItem->second == element)
+        m_map.remove(cachedItem);
+    else
+        m_duplicateCounts.remove(key);
+}
+
+template<bool keyMatches(AtomicStringImpl*, Element*)>
+inline Element* DocumentOrderedMap::get(AtomicStringImpl* key, const Document* document) const
+{
+    ASSERT(key);
+
+    m_map.checkConsistency();
+
+    Element* element = m_map.get(key);
+    if (element)
+        return element;
+
+    if (m_duplicateCounts.contains(key)) {
+        // We know there's at least one node that matches; iterate to find the first one.
+        for (Node* node = document->firstChild(); node; node = node->traverseNextNode()) {
+            if (!node->isElementNode())
+                continue;
+            element = static_cast<Element*>(node);
+            if (!keyMatches(key, element))
+                continue;
+            m_duplicateCounts.remove(key);
+            m_map.set(key, element);
+            return element;
+        }
+        ASSERT_NOT_REACHED();
+    }
+
+    return 0;
+}
+
+Element* DocumentOrderedMap::getElementById(AtomicStringImpl* key, const Document* document) const
+{
+    return get<keyMatchesId>(key, document);
+}
+
+Element* DocumentOrderedMap::getElementByMapName(AtomicStringImpl* key, const Document* document) const
+{
+    return get<keyMatchesMapName>(key, document);
+}
+
+Element* DocumentOrderedMap::getElementByLowercasedMapName(AtomicStringImpl* key, const Document* document) const
+{
+    return get<keyMatchesLowercasedMapName>(key, document);
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/dom/DocumentOrderedMap.h b/Source/WebCore/dom/DocumentOrderedMap.h
new file mode 100644
index 0000000..58767c6
--- /dev/null
+++ b/Source/WebCore/dom/DocumentOrderedMap.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DocumentOrderedMap_h
+#define DocumentOrderedMap_h
+
+#include <wtf/HashCountedSet.h>
+#include <wtf/HashMap.h>
+#include <wtf/text/AtomicStringImpl.h>
+
+namespace WebCore {
+
+class Document;
+class Element;
+
+class DocumentOrderedMap {
+public:
+    void add(AtomicStringImpl*, Element*);
+    void remove(AtomicStringImpl*, Element*);
+    void clear();
+
+    bool contains(AtomicStringImpl*) const;
+    bool containsMultiple(AtomicStringImpl*) const;
+    // concrete instantiations of the get<>() method template
+    Element* getElementById(AtomicStringImpl*, const Document*) const;
+    Element* getElementByMapName(AtomicStringImpl*, const Document*) const;
+    Element* getElementByLowercasedMapName(AtomicStringImpl*, const Document*) const;
+
+    void checkConsistency() const;
+
+private:
+    template<bool keyMatches(AtomicStringImpl*, Element*)> Element* get(AtomicStringImpl*, const Document*) const;
+
+    typedef HashMap<AtomicStringImpl*, Element*> Map;
+
+    // We maintain the invariant that m_duplicateCounts is the count of all elements with a given key
+    // excluding the one referenced in m_map, if any. This means it one less than the total count
+    // when the first node with a given key is cached, otherwise the same as the total count.
+    mutable Map m_map;
+    mutable HashCountedSet<AtomicStringImpl*> m_duplicateCounts;
+};
+
+inline bool DocumentOrderedMap::contains(AtomicStringImpl* id) const
+{
+    return m_map.contains(id) || m_duplicateCounts.contains(id);
+}
+
+inline bool DocumentOrderedMap::containsMultiple(AtomicStringImpl* id) const
+{
+    return m_duplicateCounts.contains(id);
+}
+
+} // namespace WebCore
+
+#endif // DocumentOrderedMap_h
+

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list