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

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

Issue 2711853003: [LazyParseCSS] WIP Implement token discarding
Patch Set: lookup in escape string pool Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 7431d1176b3fe0d5ec14f158b6ee2b4f09a2244d..985d69b7b1cc46bf660b55d3272701c049b9f448 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.cpp
@@ -6,6 +6,7 @@
#include "core/css/parser/CSSLazyParsingState.h"
#include "core/css/parser/CSSParserImpl.h"
+#include "core/css/parser/CSSTokenizer.h"
namespace blink {
@@ -16,10 +17,52 @@ CSSLazyPropertyParserImpl::CSSLazyPropertyParserImpl(CSSParserTokenRange block,
size_t length = block.end() - block.begin();
m_tokens.reserveCapacity(length);
m_tokens.append(block.begin(), length);
+
+ // TEST:
+ discardTokensIfPossible();
+}
+
+CSSLazyPropertyParserImpl::~CSSLazyPropertyParserImpl() {}
+
+// If the first and last tokens have a string backing, generate a StringView
+// from their character offsets. Note that this assumes they share a backing
+// string! Be extremely careful that the first and last token do not point to a
+// string in the escaped string pool!
+void CSSLazyPropertyParserImpl::discardTokensIfPossible() {
+ CSSParserToken* begin = m_tokens.begin();
+ CSSParserToken* end = m_tokens.end() - 1;
+ if (!begin->hasStringBacking() || !end->hasStringBacking())
+ return;
+
+ StringView beginView = begin->value();
+ StringView endView = end->value();
+ if (m_lazyState->tokenBackingUsesEscapedString(beginView.bytes()) ||
+ m_lazyState->tokenBackingUsesEscapedString(endView.bytes()))
+ return;
+ if (beginView.is8Bit() && endView.is8Bit()) {
+ m_tokenView = StringView(
+ beginView.characters8(),
+ endView.characters8() - beginView.characters8() + endView.length());
+ } else if (!beginView.is8Bit() && !endView.is8Bit()) {
+ m_tokenView = StringView(
+ beginView.characters16(),
+ endView.characters16() - beginView.characters16() + endView.length());
+ } else {
+ NOTREACHED();
+ }
+ m_tokens.clear();
+}
+
+StylePropertySet* CSSLazyPropertyParserImpl::retokenizeAndParseProperties() {
+ CSSTokenizer tokenizer(m_tokenView.toString());
+ return CSSParserImpl::parseDeclarationListForLazyStyle(
+ tokenizer.tokenRange(), m_lazyState->context());
}
StylePropertySet* CSSLazyPropertyParserImpl::parseProperties() {
m_lazyState->countRuleParsed();
+ if (m_tokens.isEmpty())
+ return retokenizeAndParseProperties();
return CSSParserImpl::parseDeclarationListForLazyStyle(
m_tokens, m_lazyState->context());
}
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSLazyPropertyParserImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698