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

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSParserImpl.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/CSSParserImpl.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
index df4464540a3dbd3fe6230eaffad4432169308684..289af8585c57da5156d3f0a3b3b296519e8396f1 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp
@@ -14,6 +14,7 @@
#include "core/css/StyleRuleNamespace.h"
#include "core/css/StyleSheetContents.h"
#include "core/css/parser/CSSAtRuleID.h"
+#include "core/css/parser/CSSLazyPropertyParserImpl.h"
#include "core/css/parser/CSSParserObserver.h"
#include "core/css/parser/CSSParserObserverWrapper.h"
#include "core/css/parser/CSSParserSelector.h"
@@ -192,7 +193,8 @@ StyleRuleBase* CSSParserImpl::parseRule(const String& string,
void CSSParserImpl::parseStyleSheet(const String& string,
const CSSParserContext& context,
- StyleSheetContents* styleSheet) {
+ StyleSheetContents* styleSheet,
+ bool deferPropertyParsing) {
TRACE_EVENT_BEGIN2("blink,blink_style", "CSSParserImpl::parseStyleSheet",
"baseUrl", context.baseURL().getString().utf8(), "mode",
context.mode());
@@ -206,6 +208,10 @@ void CSSParserImpl::parseStyleSheet(const String& string,
TRACE_EVENT_BEGIN0("blink,blink_style",
"CSSParserImpl::parseStyleSheet.parse");
CSSParserImpl parser(context, styleSheet);
+ if (deferPropertyParsing) {
+ parser.m_lazyState =
+ new CSSLazyParsingState(context, scope.releaseEscapedStrings(), string);
esprehn 2016/10/24 21:20:21 std::move(scope.takeEscapedStrings()) ?
Charlie Harrison 2016/10/25 15:56:55 Done.
Charlie Harrison 2016/10/25 15:56:55 Done, but takeEscapedStrings() implies that we're
+ }
bool firstRuleValid = parser.consumeRuleList(
scope.tokenRange(), TopLevelRuleList, [&styleSheet](StyleRuleBase* rule) {
if (rule->isCharsetRule())
@@ -331,6 +337,14 @@ void CSSParserImpl::parseStyleSheetForInspector(const String& string,
styleSheet->setHasSyntacticallyValidCSSHeader(firstRuleValid);
}
+StylePropertySet* CSSParserImpl::parseDeclarationListForLazyStyle(
+ CSSParserTokenRange block,
+ const CSSParserContext& context) {
+ CSSParserImpl parser(context);
+ parser.consumeDeclarationList(std::move(block), StyleRule::Style);
+ return createStylePropertySet(parser.m_parsedProperties, context.mode());
+}
+
static CSSParserImpl::AllowedRulesType computeNewAllowedRules(
CSSParserImpl::AllowedRulesType allowedRules,
StyleRuleBase* rule) {
@@ -765,11 +779,17 @@ StyleRule* CSSParserImpl::consumeStyleRule(CSSParserTokenRange prelude,
if (!selectorList.isValid())
return nullptr; // Parse error, invalid selector list
- if (m_observerWrapper)
+ // TODO(csharrison): How should we lazily parse css that needs the observer?
+ if (m_observerWrapper) {
observeSelectors(*m_observerWrapper, prelude);
-
+ } else if (m_lazyState &&
+ m_lazyState->shouldLazilyParseProperties(selectorList)) {
+ DCHECK(m_styleSheet);
+ return StyleRule::createLazy(
+ std::move(selectorList),
+ new CSSLazyPropertyParserImpl(block, m_lazyState));
+ }
consumeDeclarationList(block, StyleRule::Style);
-
return StyleRule::create(
std::move(selectorList),
createStylePropertySet(m_parsedProperties, m_context.mode()));

Powered by Google App Engine
This is Rietveld 408576698