<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[164772] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/164772">164772</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2014-02-26 19:35:22 -0800 (Wed, 26 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Extract named items caches in HTMLCollection as a class
https://bugs.webkit.org/show_bug.cgi?id=129365
Reviewed by Antti Koivisto.
Extracted CollectionNamedElementCache, like CollectionIndexCache, out of HTMLCollection.
We can move more named item related functions into this class in the future.
HTMLCollection's member variables m_isNameCacheValid, m_idCache, and m_nameCache were replaced by
a single unique_ptr that holds an instance of CollectionNamedElementCache since this object rarely
exists in most HTMLCollections.
Also removed m_isItemRefElementsCacheValid since it was only used by Microdata API removed in <a href="http://trac.webkit.org/projects/webkit/changeset/153772">r153772</a>
and renamed a whole bunch of member functions and variables for consistency.
* dom/Document.cpp:
(WebCore::Document::collectionCachedIdNameMap):
(WebCore::Document::collectionWillClearIdNameMap):
* dom/Document.h:
* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::adoptDocument):
* html/HTMLAllCollection.cpp:
(WebCore::HTMLAllCollection::namedItemWithIndex):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::~HTMLCollection):
(WebCore::HTMLCollection::invalidateCache):
(WebCore::HTMLCollection::invalidateNamedElementCache): Renamed from invalidateIdNameCacheMaps.
(WebCore::HTMLCollection::namedItem):
(WebCore::HTMLCollection::updateNamedElementCache): Renamed from updateNameCache.
(WebCore::HTMLCollection::namedItems):
* html/HTMLCollection.h:
(WebCore::CollectionNamedElementCache::findElementsWithId): Renamed from HTMLCollection::idCache.
(WebCore::CollectionNamedElementCache::findElementsWithName): Renamed from HTMLCollection::nameCache.
(WebCore::CollectionNamedElementCache::appendIdCache): Moved from HTMLCollection.
(WebCore::CollectionNamedElementCache::appendNameCache): Ditto.
(WebCore::CollectionNamedElementCache::find): Ditto.
(WebCore::CollectionNamedElementCache::append): Ditto.
(WebCore::HTMLCollection::invalidateCache):
(WebCore::HTMLCollection::hasNamedElementCache): Renamed from hasIdNameCache.
(WebCore::HTMLCollection::createNameItemCache): Added.
(WebCore::HTMLCollection::namedItemCaches): Added.
* html/HTMLFormControlsCollection.cpp:
(WebCore::HTMLFormControlsCollection::updateNamedElementCache):
* html/HTMLFormControlsCollection.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomNodeRareDatah">trunk/Source/WebCore/dom/NodeRareData.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAllCollectioncpp">trunk/Source/WebCore/html/HTMLAllCollection.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLCollectioncpp">trunk/Source/WebCore/html/HTMLCollection.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLCollectionh">trunk/Source/WebCore/html/HTMLCollection.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLFormControlsCollectioncpp">trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLFormControlsCollectionh">trunk/Source/WebCore/html/HTMLFormControlsCollection.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/ChangeLog        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -1,5 +1,94 @@
</span><span class="cx"> 2014-02-26 Ryosuke Niwa <rniwa@webkit.org>
</span><span class="cx">
</span><ins>+ Extract named items caches in HTMLCollection as a class
+ https://bugs.webkit.org/show_bug.cgi?id=129365
+
+ Reviewed by Antti Koivisto.
+
+ Extracted CollectionNamedElementCache, like CollectionIndexCache, out of HTMLCollection.
+ We can move more named item related functions into this class in the future.
+
+ HTMLCollection's member variables m_isNameCacheValid, m_idCache, and m_nameCache were replaced by
+ a single unique_ptr that holds an instance of CollectionNamedElementCache since this object rarely
+ exists in most HTMLCollections.
+
+ Also removed m_isItemRefElementsCacheValid since it was only used by Microdata API removed in r153772
+ and renamed a whole bunch of member functions and variables for consistency.
+
+ * dom/Document.cpp:
+ (WebCore::Document::collectionCachedIdNameMap):
+ (WebCore::Document::collectionWillClearIdNameMap):
+ * dom/Document.h:
+ * dom/NodeRareData.h:
+ (WebCore::NodeListsNodeData::adoptDocument):
+ * html/HTMLAllCollection.cpp:
+ (WebCore::HTMLAllCollection::namedItemWithIndex):
+ * html/HTMLCollection.cpp:
+ (WebCore::HTMLCollection::HTMLCollection):
+ (WebCore::HTMLCollection::~HTMLCollection):
+ (WebCore::HTMLCollection::invalidateCache):
+ (WebCore::HTMLCollection::invalidateNamedElementCache): Renamed from invalidateIdNameCacheMaps.
+ (WebCore::HTMLCollection::namedItem):
+ (WebCore::HTMLCollection::updateNamedElementCache): Renamed from updateNameCache.
+ (WebCore::HTMLCollection::namedItems):
+
+ * html/HTMLCollection.h:
+ (WebCore::CollectionNamedElementCache::findElementsWithId): Renamed from HTMLCollection::idCache.
+ (WebCore::CollectionNamedElementCache::findElementsWithName): Renamed from HTMLCollection::nameCache.
+ (WebCore::CollectionNamedElementCache::appendIdCache): Moved from HTMLCollection.
+ (WebCore::CollectionNamedElementCache::appendNameCache): Ditto.
+ (WebCore::CollectionNamedElementCache::find): Ditto.
+ (WebCore::CollectionNamedElementCache::append): Ditto.
+
+ (WebCore::HTMLCollection::invalidateCache):
+ (WebCore::HTMLCollection::hasNamedElementCache): Renamed from hasIdNameCache.
+ (WebCore::HTMLCollection::createNameItemCache): Added.
+ (WebCore::HTMLCollection::namedItemCaches): Added.
+
+ * html/HTMLFormControlsCollection.cpp:
+ (WebCore::HTMLFormControlsCollection::updateNamedElementCache):
+ * html/HTMLFormControlsCollection.h:
+
+2014-02-26 Ryosuke Niwa <rniwa@webkit.org>
+
+ Extract named items caches in HTMLCollection as a class
+ https://bugs.webkit.org/show_bug.cgi?id=129365
+
+ Reviewed by Antti Koivisto.
+
+ Extracted CollectionNamedItemCaches, like CollectionIndexCache, out of HTMLCollection.
+ We can move more named item related functions into this class in the future.
+
+ HTMLCollection's member variables m_isNameCacheValid, m_idCache, and m_nameCache were replaced by
+ a single unique_ptr that holds an instance of CollectionNamedItemCaches since this object rarely
+ exists in most HTMLCollections.
+
+ Also removed m_isItemRefElementsCacheValid since it was only used by Microdata API removed in r153772.
+
+ * html/HTMLAllCollection.cpp:
+ (WebCore::HTMLAllCollection::namedItemWithIndex):
+ * html/HTMLCollection.cpp:
+ (WebCore::HTMLCollection::HTMLCollection):
+ (WebCore::HTMLCollection::invalidateCache):
+ (WebCore::HTMLCollection::invalidateIdNameCacheMaps):
+ (WebCore::HTMLCollection::namedItem):
+ (WebCore::HTMLCollection::updateNameCache):
+ (WebCore::HTMLCollection::namedItems):
+ * html/HTMLCollection.h:
+ (WebCore::CollectionNamedItemCaches::idCache):
+ (WebCore::CollectionNamedItemCaches::nameCache):
+ (WebCore::CollectionNamedItemCaches::appendIdCache):
+ (WebCore::CollectionNamedItemCaches::appendNameCache):
+ (WebCore::CollectionNamedItemCaches::find):
+ (WebCore::CollectionNamedItemCaches::append):
+ (WebCore::HTMLCollection::hasIdNameCache):
+ (WebCore::HTMLCollection::createNameItemCaches):
+ (WebCore::HTMLCollection::namedItemCachesAssertingExistence):
+ * html/HTMLFormControlsCollection.cpp:
+ (WebCore::HTMLFormControlsCollection::updateNameCache):
+
+2014-02-26 Ryosuke Niwa <rniwa@webkit.org>
+
</ins><span class="cx"> Indenting an indented image element resulted in an extra indentation
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=129201
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/dom/Document.cpp        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -3479,13 +3479,13 @@
</span><span class="cx">
</span><span class="cx"> void Document::collectionCachedIdNameMap(const HTMLCollection& collection)
</span><span class="cx"> {
</span><del>- ASSERT_UNUSED(collection, collection.hasIdNameCache());
</del><ins>+ ASSERT_UNUSED(collection, collection.hasNamedElementCache());
</ins><span class="cx"> m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]++;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Document::collectionWillClearIdNameMap(const HTMLCollection& collection)
</span><span class="cx"> {
</span><del>- ASSERT_UNUSED(collection, collection.hasIdNameCache());
</del><ins>+ ASSERT_UNUSED(collection, collection.hasNamedElementCache());
</ins><span class="cx"> ASSERT(m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]);
</span><span class="cx"> m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]--;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/dom/Document.h        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -761,8 +761,8 @@
</span><span class="cx">
</span><span class="cx"> void registerNodeList(LiveNodeList&);
</span><span class="cx"> void unregisterNodeList(LiveNodeList&);
</span><del>- void registerCollection(HTMLCollection&, bool hasIdNameCache);
- void unregisterCollection(HTMLCollection&, bool hasIdNameCache);
</del><ins>+ void registerCollection(HTMLCollection&, bool hasNamedElementCache);
+ void unregisterCollection(HTMLCollection&, bool hasNamedElementCache);
</ins><span class="cx"> void collectionCachedIdNameMap(const HTMLCollection&);
</span><span class="cx"> void collectionWillClearIdNameMap(const HTMLCollection&);
</span><span class="cx"> bool shouldInvalidateNodeListAndCollectionCaches(const QualifiedName* attrName = nullptr) const;
</span></span></pre></div>
<a id="trunkSourceWebCoredomNodeRareDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/NodeRareData.h (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/NodeRareData.h        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/dom/NodeRareData.h        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -254,8 +254,8 @@
</span><span class="cx">
</span><span class="cx"> for (auto it : m_cachedCollections) {
</span><span class="cx"> HTMLCollection& collection = *it.value;
</span><del>- oldDocument->unregisterCollection(collection, collection.hasIdNameCache());
- newDocument->registerCollection(collection, collection.hasIdNameCache());
</del><ins>+ oldDocument->unregisterCollection(collection, collection.hasNamedElementCache());
+ newDocument->registerCollection(collection, collection.hasNamedElementCache());
</ins><span class="cx"> collection.invalidateCache();
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAllCollectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAllCollection.cpp (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAllCollection.cpp        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/html/HTMLAllCollection.cpp        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -46,17 +46,18 @@
</span><span class="cx">
</span><span class="cx"> Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const
</span><span class="cx"> {
</span><del>- updateNameCache();
</del><ins>+ updateNamedElementCache();
+ const CollectionNamedElementCache& cache = namedItemCaches();
</ins><span class="cx">
</span><del>- if (Vector<Element*>* cache = idCache(name)) {
- if (index < cache->size())
- return cache->at(index);
- index -= cache->size();
</del><ins>+ if (const Vector<Element*>* elements = cache.findElementsWithId(name)) {
+ if (index < elements->size())
+ return elements->at(index);
+ index -= elements->size();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if (Vector<Element*>* cache = nameCache(name)) {
- if (index < cache->size())
- return cache->at(index);
</del><ins>+ if (const Vector<Element*>* elements = cache.findElementsWithName(name)) {
+ if (index < elements->size())
+ return elements->at(index);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return 0;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLCollectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLCollection.cpp        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -133,19 +133,17 @@
</span><span class="cx">
</span><span class="cx"> HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, ElementTraversalType traversalType)
</span><span class="cx"> : m_ownerNode(ownerNode)
</span><del>- , m_rootType(rootTypeFromCollectionType(type))
</del><ins>+ , m_collectionType(type)
</ins><span class="cx"> , m_invalidationType(invalidationTypeExcludingIdAndNameAttributes(type))
</span><ins>+ , m_rootType(rootTypeFromCollectionType(type))
</ins><span class="cx"> , m_shouldOnlyIncludeDirectChildren(shouldOnlyIncludeDirectChildren(type))
</span><del>- , m_isNameCacheValid(false)
- , m_collectionType(type)
</del><span class="cx"> , m_usesCustomForwardOnlyTraversal(traversalType == CustomForwardOnlyTraversal)
</span><del>- , m_isItemRefElementsCacheValid(false)
</del><span class="cx"> {
</span><span class="cx"> ASSERT(m_rootType == static_cast<unsigned>(rootTypeFromCollectionType(type)));
</span><span class="cx"> ASSERT(m_invalidationType == static_cast<unsigned>(invalidationTypeExcludingIdAndNameAttributes(type)));
</span><span class="cx"> ASSERT(m_collectionType == static_cast<unsigned>(type));
</span><span class="cx">
</span><del>- document().registerCollection(*this, hasIdNameCache());
</del><ins>+ document().registerCollection(*this, hasNamedElementCache());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> PassRefPtr<HTMLCollection> HTMLCollection::create(ContainerNode& base, CollectionType type)
</span><span class="lines">@@ -155,7 +153,7 @@
</span><span class="cx">
</span><span class="cx"> HTMLCollection::~HTMLCollection()
</span><span class="cx"> {
</span><del>- document().unregisterCollection(*this, hasIdNameCache());
</del><ins>+ document().unregisterCollection(*this, hasNamedElementCache());
</ins><span class="cx"> // HTMLNameCollection removes cache by itself.
</span><span class="cx"> if (type() != WindowNamedItems && type() != DocumentNamedItems)
</span><span class="cx"> ownerNode().nodeLists()->removeCachedCollection(this);
</span><span class="lines">@@ -367,18 +365,15 @@
</span><span class="cx"> void HTMLCollection::invalidateCache() const
</span><span class="cx"> {
</span><span class="cx"> m_indexCache.invalidate();
</span><del>- m_isItemRefElementsCacheValid = false;
- if (hasIdNameCache())
- invalidateIdNameCacheMaps();
</del><ins>+ if (hasNamedElementCache())
+ invalidateNamedElementCache();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void HTMLCollection::invalidateIdNameCacheMaps() const
</del><ins>+void HTMLCollection::invalidateNamedElementCache() const
</ins><span class="cx"> {
</span><del>- ASSERT(hasIdNameCache());
</del><ins>+ ASSERT(hasNamedElementCache());
</ins><span class="cx"> document().collectionWillClearIdNameMap(*this);
</span><del>- m_isNameCacheValid = false;
- m_idCache.clear();
- m_nameCache.clear();
</del><ins>+ m_namedElementCache = nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Node* HTMLCollection::namedItem(const AtomicString& name) const
</span><span class="lines">@@ -414,14 +409,15 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // The pathological case. We need to walk the entire subtree.
</span><del>- updateNameCache();
</del><ins>+ updateNamedElementCache();
+ ASSERT(m_namedElementCache);
</ins><span class="cx">
</span><del>- if (Vector<Element*>* idResults = idCache(name)) {
</del><ins>+ if (const Vector<Element*>* idResults = m_namedElementCache->findElementsWithId(name)) {
</ins><span class="cx"> if (idResults->size())
</span><span class="cx"> return idResults->at(0);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (Vector<Element*>* nameResults = nameCache(name)) {
</del><ins>+ if (const Vector<Element*>* nameResults = m_namedElementCache->findElementsWithName(name)) {
</ins><span class="cx"> if (nameResults->size())
</span><span class="cx"> return nameResults->at(0);
</span><span class="cx"> }
</span><span class="lines">@@ -429,26 +425,25 @@
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void HTMLCollection::updateNameCache() const
</del><ins>+void HTMLCollection::updateNamedElementCache() const
</ins><span class="cx"> {
</span><del>- if (hasIdNameCache())
</del><ins>+ if (hasNamedElementCache())
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> ContainerNode& root = rootNode();
</span><ins>+ CollectionNamedElementCache& cache = createNameItemCache();
</ins><span class="cx">
</span><span class="cx"> unsigned count;
</span><span class="cx"> for (Element* element = firstElement(root); element; element = traverseForward(*element, 1, count, root)) {
</span><span class="cx"> const AtomicString& idAttrVal = element->getIdAttribute();
</span><span class="cx"> if (!idAttrVal.isEmpty())
</span><del>- appendIdCache(idAttrVal, element);
</del><ins>+ cache.appendIdCache(idAttrVal, element);
</ins><span class="cx"> if (!element->isHTMLElement())
</span><span class="cx"> continue;
</span><span class="cx"> const AtomicString& nameAttrVal = element->getNameAttribute();
</span><span class="cx"> if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != DocAll || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element))))
</span><del>- appendNameCache(nameAttrVal, element);
</del><ins>+ cache.appendNameCache(nameAttrVal, element);
</ins><span class="cx"> }
</span><del>-
- setHasIdNameCache();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool HTMLCollection::hasNamedItem(const AtomicString& name) const
</span><span class="lines">@@ -463,10 +458,11 @@
</span><span class="cx"> if (name.isEmpty())
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- updateNameCache();
</del><ins>+ updateNamedElementCache();
+ ASSERT(m_namedElementCache);
</ins><span class="cx">
</span><del>- Vector<Element*>* idResults = idCache(name);
- Vector<Element*>* nameResults = nameCache(name);
</del><ins>+ const Vector<Element*>* idResults = m_namedElementCache->findElementsWithId(name);
+ const Vector<Element*>* nameResults = m_namedElementCache->findElementsWithName(name);
</ins><span class="cx">
</span><span class="cx"> for (unsigned i = 0; idResults && i < idResults->size(); ++i)
</span><span class="cx"> result.append(*idResults->at(i));
</span><span class="lines">@@ -480,12 +476,4 @@
</span><span class="cx"> return ownerNode().getElementsByTagName(name);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
-{
- OwnPtr<Vector<Element*>>& vector = map.add(key.impl(), nullptr).iterator->value;
- if (!vector)
- vector = adoptPtr(new Vector<Element*>);
- vector->append(element);
-}
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLCollectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLCollection.h (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLCollection.h        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/html/HTMLCollection.h        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx"> * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
</span><span class="cx"> * (C) 1999 Antti Koivisto (koivisto@kde.org)
</span><del>- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * This library is free software; you can redistribute it and/or
</span><span class="cx"> * modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -38,6 +38,32 @@
</span><span class="cx">
</span><span class="cx"> class Element;
</span><span class="cx">
</span><ins>+class CollectionNamedElementCache {
+public:
+ const Vector<Element*>* findElementsWithId(const AtomicString& id) const { return find(m_idToElementsMap, id); }
+ const Vector<Element*>* findElementsWithName(const AtomicString& name) const { return find(m_nameToElementsMap, name); }
+
+ void appendIdCache(const AtomicString& id, Element* element) { return append(m_idToElementsMap, id, element); }
+ void appendNameCache(const AtomicString& name, Element* element) { return append(m_nameToElementsMap, name, element); }
+
+private:
+ typedef HashMap<AtomicStringImpl*, Vector<Element*>> StringToElementsMap;
+
+ static const Vector<Element*>* find(const StringToElementsMap& map, const AtomicString& key)
+ {
+ auto it = map.find(key.impl());
+ return it != map.end() ? &it->value : nullptr;
+ }
+
+ static void append(StringToElementsMap& map, const AtomicString& key, Element* element)
+ {
+ map.add(key.impl(), Vector<Element*>()).iterator->value.append(element);
+ }
+
+ StringToElementsMap m_idToElementsMap;
+ StringToElementsMap m_nameToElementsMap;
+};
+
</ins><span class="cx"> class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> {
</span><span class="cx"> public:
</span><span class="cx"> static PassRefPtr<HTMLCollection> create(ContainerNode& base, CollectionType);
</span><span class="lines">@@ -61,8 +87,8 @@
</span><span class="cx"> {
</span><span class="cx"> if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *attrName))
</span><span class="cx"> invalidateCache();
</span><del>- else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr))
- invalidateIdNameCacheMaps();
</del><ins>+ else if (hasNamedElementCache() && (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr))
+ invalidateNamedElementCache();
</ins><span class="cx"> }
</span><span class="cx"> virtual void invalidateCache() const;
</span><span class="cx">
</span><span class="lines">@@ -73,60 +99,53 @@
</span><span class="cx"> Element* collectionTraverseBackward(Element&, unsigned count) const;
</span><span class="cx"> bool collectionCanTraverseBackward() const { return !m_usesCustomForwardOnlyTraversal; }
</span><span class="cx">
</span><del>- bool hasIdNameCache() const { return m_isNameCacheValid; }
</del><ins>+ bool hasNamedElementCache() const { return !!m_namedElementCache; }
</ins><span class="cx">
</span><span class="cx"> protected:
</span><span class="cx"> enum ElementTraversalType { NormalTraversal, CustomForwardOnlyTraversal };
</span><span class="cx"> HTMLCollection(ContainerNode& base, CollectionType, ElementTraversalType = NormalTraversal);
</span><span class="cx">
</span><del>- void invalidateIdNameCacheMaps() const;
- virtual void updateNameCache() const;
</del><ins>+ virtual void updateNamedElementCache() const;
</ins><span class="cx">
</span><del>- 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); }
-
</del><span class="cx"> Document& document() const { return m_ownerNode->document(); }
</span><span class="cx"> ContainerNode& rootNode() const;
</span><span class="cx"> bool usesCustomForwardOnlyTraversal() const { return m_usesCustomForwardOnlyTraversal; }
</span><span class="cx">
</span><del>- bool isItemRefElementsCacheValid() const { return m_isItemRefElementsCacheValid; }
- void setItemRefElementsCacheValid() const { m_isItemRefElementsCacheValid = true; }
-
</del><span class="cx"> NodeListRootType rootType() const { return static_cast<NodeListRootType>(m_rootType); }
</span><span class="cx">
</span><del>- void setHasIdNameCache() const
</del><ins>+ CollectionNamedElementCache& createNameItemCache() const
</ins><span class="cx"> {
</span><del>- m_isNameCacheValid = true;
</del><ins>+ ASSERT(!m_namedElementCache);
+ m_namedElementCache = std::make_unique<CollectionNamedElementCache>();
</ins><span class="cx"> document().collectionCachedIdNameMap(*this);
</span><ins>+ return *m_namedElementCache;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ const CollectionNamedElementCache& namedItemCaches() const
+ {
+ ASSERT(!!m_namedElementCache);
+ return *m_namedElementCache;
+ }
+
</ins><span class="cx"> private:
</span><del>- static void append(NodeCacheMap&, const AtomicString&, Element*);
-
</del><span class="cx"> Element* iterateForPreviousElement(Element* current) const;
</span><span class="cx"> Element* firstElement(ContainerNode& root) const;
</span><span class="cx"> Element* traverseForward(Element& current, unsigned count, unsigned& traversedCount, ContainerNode& root) const;
</span><span class="cx">
</span><span class="cx"> virtual Element* customElementAfter(Element*) const { ASSERT_NOT_REACHED(); return nullptr; }
</span><ins>+
+ void invalidateNamedElementCache() const;
</ins><span class="cx">
</span><span class="cx"> Ref<ContainerNode> m_ownerNode;
</span><span class="cx">
</span><span class="cx"> mutable CollectionIndexCache<HTMLCollection, Element> m_indexCache;
</span><ins>+ mutable std::unique_ptr<CollectionNamedElementCache> m_namedElementCache;
</ins><span class="cx">
</span><ins>+ const unsigned m_collectionType : 5;
+ const unsigned m_invalidationType : 4;
</ins><span class="cx"> const unsigned m_rootType : 1;
</span><del>- const unsigned m_invalidationType : 4;
</del><span class="cx"> const unsigned m_shouldOnlyIncludeDirectChildren : 1;
</span><del>-
- mutable unsigned m_isNameCacheValid : 1;
- const unsigned m_collectionType : 5;
</del><span class="cx"> const unsigned m_usesCustomForwardOnlyTraversal : 1;
</span><del>- mutable unsigned m_isItemRefElementsCacheValid : 1;
-
- mutable NodeCacheMap m_idCache;
- mutable NodeCacheMap m_nameCache;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLFormControlsCollectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -135,13 +135,13 @@
</span><span class="cx"> return firstNamedItem(formControlElements(), imagesElements, nameAttr, name);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void HTMLFormControlsCollection::updateNameCache() const
</del><ins>+void HTMLFormControlsCollection::updateNamedElementCache() const
</ins><span class="cx"> {
</span><del>- if (hasIdNameCache())
</del><ins>+ if (hasNamedElementCache())
</ins><span class="cx"> return;
</span><span class="cx">
</span><ins>+ CollectionNamedElementCache& cache = createNameItemCache();
</ins><span class="cx"> HashSet<AtomicStringImpl*> foundInputElements;
</span><del>-
</del><span class="cx"> const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
</span><span class="cx">
</span><span class="cx"> for (unsigned i = 0; i < elementsArray.size(); ++i) {
</span><span class="lines">@@ -151,11 +151,11 @@
</span><span class="cx"> const AtomicString& idAttrVal = element.getIdAttribute();
</span><span class="cx"> const AtomicString& nameAttrVal = element.getNameAttribute();
</span><span class="cx"> if (!idAttrVal.isEmpty()) {
</span><del>- appendIdCache(idAttrVal, &element);
</del><ins>+ cache.appendIdCache(idAttrVal, &element);
</ins><span class="cx"> foundInputElements.add(idAttrVal.impl());
</span><span class="cx"> }
</span><span class="cx"> if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) {
</span><del>- appendNameCache(nameAttrVal, &element);
</del><ins>+ cache.appendNameCache(nameAttrVal, &element);
</ins><span class="cx"> foundInputElements.add(nameAttrVal.impl());
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -168,13 +168,11 @@
</span><span class="cx"> const AtomicString& idAttrVal = element.getIdAttribute();
</span><span class="cx"> const AtomicString& nameAttrVal = element.getNameAttribute();
</span><span class="cx"> if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl()))
</span><del>- appendIdCache(idAttrVal, &element);
</del><ins>+ cache.appendIdCache(idAttrVal, &element);
</ins><span class="cx"> if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl()))
</span><del>- appendNameCache(nameAttrVal, &element);
</del><ins>+ cache.appendNameCache(nameAttrVal, &element);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>-
- setHasIdNameCache();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void HTMLFormControlsCollection::invalidateCache() const
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLFormControlsCollectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLFormControlsCollection.h (164771 => 164772)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLFormControlsCollection.h        2014-02-27 03:01:24 UTC (rev 164771)
+++ trunk/Source/WebCore/html/HTMLFormControlsCollection.h        2014-02-27 03:35:22 UTC (rev 164772)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx"> explicit HTMLFormControlsCollection(ContainerNode&);
</span><span class="cx">
</span><span class="cx"> virtual void invalidateCache() const override;
</span><del>- virtual void updateNameCache() const override;
</del><ins>+ virtual void updateNamedElementCache() const override;
</ins><span class="cx">
</span><span class="cx"> const Vector<FormAssociatedElement*>& formControlElements() const;
</span><span class="cx"> const Vector<HTMLImageElement*>& formImageElements() const;
</span></span></pre>
</div>
</div>
</body>
</html>