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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp

Issue 2315923002: Lazy Parse CSS (Closed)
Patch Set: Remove the closure and refactor logic into a separate file Created 4 years, 2 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: third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp b/third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5994663692aeff63bebfb9d91fa93dd1777fa7f0
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/css/parser/CSSLazyPropertyParserImpl.h"
+
+#include "core/css/parser/CSSParserImpl.h"
+
+namespace blink {
+
+CSSLazyParsingState::CSSLazyParsingState(
+ const CSSParserContext& context,
+ std::unique_ptr<Vector<String>> escapedStrings,
+ const String& sheetText)
+ : m_context(context),
+ m_escapedStrings(std::move(escapedStrings)),
+ m_sheetText(sheetText) {}
+
+CSSLazyPropertyParserImpl::CSSLazyPropertyParserImpl(CSSParserTokenRange block,
esprehn 2016/10/24 21:20:20 Can we put the classes in their own files?
Charlie Harrison 2016/10/25 15:56:55 Done.
+ CSSLazyParsingState* state)
+ : CSSLazyPropertyParser(), m_lazyState(state) {
+ // Reserve capacity to minimize heap bloat.
+ size_t length = block.end() - block.begin();
+ m_tokens.reserveCapacity(length);
+ m_tokens.append(block.begin(), length);
+}
+
+StylePropertySet* CSSLazyPropertyParserImpl::parseProperties() {
+ return CSSParserImpl::parseDeclarationListForLazyStyle(
+ m_tokens, m_lazyState->context());
+}
+
+// Disallow lazy parsing for blocks which have
+// - before/after in their selector list. This ensures we don't cause a
+// collectFeatures() when we trigger parsing for attr() functions which would
+// trigger expensive invalidation propagation.
+//
+// Note: another optimization might be to disallow lazy parsing for rules which
+// will end up being empty. This is hard to know without parsing but we may be
+// able to catch the {}, { } cases. This would be to hit
+// StyleRule::shouldConsiderForMatchingRules more.
+bool CSSLazyParsingState::shouldLazilyParseProperties(
+ const CSSSelectorList& selectors) {
+ for (const auto* s = selectors.first(); s; s = CSSSelectorList::next(*s)) {
+ const CSSSelector::PseudoType type(s->getPseudoType());
+ if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter)
+ return false;
+ }
+ return true;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698