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

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

Issue 2100573002: Avoid copying strings when parsing CSS colors on the slow path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing else. Created 4 years, 6 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/CSSTokenizer.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp b/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp
index cf8a087fc21f507dcf1cbc5feeb43e1bd766546b..e6229ecdbe27f57867d3dc5703a507393989fff0 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp
@@ -667,13 +667,18 @@ StringView CSSTokenizer::consumeName()
// Names without escapes get handled without allocations
for (unsigned size = 0; ; ++size) {
UChar cc = m_input.peekWithoutReplacement(size);
- if (cc == '\0' || cc == '\\')
+ if (isNameCodePoint(cc))
+ continue;
+ // peekWithoutReplacement will return NUL when we hit the end of the
+ // input. In that case we want to still use the rangeAt() fast path
+ // below.
+ if (cc == '\0' && m_input.offset() + size < m_input.length())
Timothy Loh 2016/06/27 00:14:25 good find!
break;
- if (!isNameCodePoint(cc)) {
- unsigned startOffset = m_input.offset();
- m_input.advance(size);
- return m_input.rangeAt(startOffset, size);
- }
+ if (cc == '\\')
+ break;
+ unsigned startOffset = m_input.offset();
+ m_input.advance(size);
+ return m_input.rangeAt(startOffset, size);
}
StringBuilder result;

Powered by Google App Engine
This is Rietveld 408576698