Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Unified Diff: Source/core/dom/Document.cpp

Issue 1023393002: Cache element indices for :nth-child and :nth-last-child selectors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clear cache after each operation Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 0e83a6fc8b4c3f1f9d4761ba9695a15ff178e575..e68b659f7f54389d762d639322686cd454f601ed 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -86,6 +86,7 @@
#include "core/dom/NodeRenderingTraversal.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/NodeWithIndex.h"
+#include "core/dom/NthIndexCache.h"
#include "core/dom/ProcessingInstruction.h"
#include "core/dom/RequestAnimationFrameCallback.h"
#include "core/dom/ScriptRunner.h"
@@ -474,6 +475,7 @@ Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC
, m_hasViewportUnits(false)
, m_styleRecalcElementCounter(0)
, m_parserSyncPolicy(AllowAsynchronousParsing)
+ , m_useNthIndexCache(false)
{
if (m_frame) {
ASSERT(m_frame->page());
@@ -656,6 +658,22 @@ SelectorQueryCache& Document::selectorQueryCache()
return *m_selectorQueryCache;
}
+NthIndexCache* Document::nthIndexCache()
+{
+ if (!m_useNthIndexCache)
+ return nullptr;
+ if (!m_nthIndexCache)
+ m_nthIndexCache = adoptPtr(new NthIndexCache(*this));
sof 2015/03/28 08:33:59 adoptPtrWillBeNoop() -- would be tidier to provide
rune 2015/03/30 09:00:03 Done.
sof 2015/03/30 20:55:16 Oh, not quite, you're still using adoptPtr() -- ou
+ return m_nthIndexCache.get();
+}
+
+void Document::setUseNthIndexCache(bool use)
+{
+ m_useNthIndexCache = use;
+ if (!use && m_nthIndexCache)
+ m_nthIndexCache->clear();
+}
+
MediaQueryMatcher& Document::mediaQueryMatcher()
{
if (!m_mediaQueryMatcher)
@@ -1713,6 +1731,8 @@ void Document::updateRenderTree(StyleRecalcChange change)
if (inStyleRecalc())
return;
+ UseNthIndexCacheScope nthIndexScope(*this);
+
// Entering here from inside layout or paint would be catastrophic since recalcStyle can
// tear down the render tree or (unfortunately) run script. Kill the whole renderer if
// someone managed to get into here from inside layout or paint.

Powered by Google App Engine
This is Rietveld 408576698