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

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

Issue 2315923002: Lazy Parse CSS (Closed)
Patch Set: CL for src perf tryjob to run page_cycler_v2.typical_25 benchmark on all-android platform(s) 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/parser/CSSTokenizer.h" 5 #include "core/css/parser/CSSTokenizer.h"
6 6
7 namespace blink { 7 namespace blink {
8 #include "core/CSSTokenizerCodepoints.cpp" 8 #include "core/CSSTokenizerCodepoints.cpp"
9 } 9 }
10 10
11 #include "core/css/parser/CSSParserIdioms.h" 11 #include "core/css/parser/CSSParserIdioms.h"
12 #include "core/css/parser/CSSParserObserverWrapper.h" 12 #include "core/css/parser/CSSParserObserverWrapper.h"
13 #include "core/css/parser/CSSParserTokenRange.h" 13 #include "core/css/parser/CSSParserTokenRange.h"
14 #include "core/css/parser/CSSTokenizerInputStream.h" 14 #include "core/css/parser/CSSTokenizerInputStream.h"
15 #include "core/html/parser/HTMLParserIdioms.h" 15 #include "core/html/parser/HTMLParserIdioms.h"
16 #include "wtf/text/CharacterNames.h" 16 #include "wtf/text/CharacterNames.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 CSSTokenizer::Scope::Scope(const String& string) 20 CSSTokenizer::Scope::Scope(const String& string)
21 : m_string(string) 21 : m_string(string)
22 { 22 {
23 // According to the spec, we should perform preprocessing here. 23 // According to the spec, we should perform preprocessing here.
24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing 24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing
25 // 25 //
26 // However, we can skip this step since: 26 // However, we can skip this step since:
27 // * We're using HTML spaces (which accept \r and \f as a valid white space) 27 // * We're using HTML spaces (which accept \r and \f as a valid white space)
28 // * Do not count white spaces 28 // * Do not count white spaces
29 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters 29 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters
30 30
31 if (string.isEmpty()) 31 if (string.isEmpty())
32 return; 32 return;
33 33
34 // To avoid resizing we err on the side of reserving too much space. 34 // To avoid resizing we err on the side of reserving too much space.
35 // Most strings we tokenize have about 3.5 to 5 characters per token. 35 // Most strings we tokenize have about 3.5 to 5 characters per token.
36 m_tokens.reserveInitialCapacity(string.length() / 3); 36 m_tokens.reserveInitialCapacity(string.length() / 3);
37 37
38 CSSTokenizerInputStream input(string); 38 CSSTokenizerInputStream input(string);
39 CSSTokenizer tokenizer(input, *this); 39 CSSTokenizer tokenizer(input, *this);
40 while (true) { 40 while (true) {
41 CSSParserToken token = tokenizer.nextToken(); 41 CSSParserToken token = tokenizer.nextToken();
42 if (token.type() == CommentToken) 42 if (token.type() == CommentToken)
43 continue; 43 continue;
44 if (token.type() == EOFToken) 44 if (token.type() == EOFToken)
45 return; 45 return;
46 m_tokens.append(token); 46 m_tokens.append(token);
47 } 47 }
48 } 48 }
49 49
50 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp er) 50 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp er)
51 : m_string(string) 51 : m_string(string)
52 { 52 {
53 if (string.isEmpty()) 53 if (string.isEmpty())
54 return; 54 return;
55 55
56 CSSTokenizerInputStream input(string); 56 CSSTokenizerInputStream input(string);
57 CSSTokenizer tokenizer(input, *this); 57 CSSTokenizer tokenizer(input, *this);
58 58
59 unsigned offset = 0; 59 unsigned offset = 0;
60 while (true) { 60 while (true) {
61 CSSParserToken token = tokenizer.nextToken(); 61 CSSParserToken token = tokenizer.nextToken();
(...skipping 15 matching lines...) Expand all
77 CSSParserTokenRange CSSTokenizer::Scope::tokenRange() 77 CSSParserTokenRange CSSTokenizer::Scope::tokenRange()
78 { 78 {
79 return m_tokens; 79 return m_tokens;
80 } 80 }
81 81
82 unsigned CSSTokenizer::Scope::tokenCount() 82 unsigned CSSTokenizer::Scope::tokenCount()
83 { 83 {
84 return m_tokens.size(); 84 return m_tokens.size();
85 } 85 }
86 86
87 void CSSTokenizer::Scope::storeString(const String& string)
88 {
89 if (!m_stringPool)
90 m_stringPool.reset(new Vector<String>);
91 m_stringPool->append(string);
92 }
93
87 static bool isNewLine(UChar cc) 94 static bool isNewLine(UChar cc)
88 { 95 {
89 // We check \r and \f here, since we have no preprocessing stage 96 // We check \r and \f here, since we have no preprocessing stage
90 return (cc == '\r' || cc == '\n' || cc == '\f'); 97 return (cc == '\r' || cc == '\n' || cc == '\f');
91 } 98 }
92 99
93 // http://dev.w3.org/csswg/css-syntax/#check-if-two-code-points-are-a-valid-esca pe 100 // http://dev.w3.org/csswg/css-syntax/#check-if-two-code-points-are-a-valid-esca pe
94 static bool twoCharsAreValidEscape(UChar first, UChar second) 101 static bool twoCharsAreValidEscape(UChar first, UChar second)
95 { 102 {
96 return first == '\\' && !isNewLine(second); 103 return first == '\\' && !isNewLine(second);
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return areIdentifier; 733 return areIdentifier;
727 } 734 }
728 735
729 StringView CSSTokenizer::registerString(const String& string) 736 StringView CSSTokenizer::registerString(const String& string)
730 { 737 {
731 m_scope.storeString(string); 738 m_scope.storeString(string);
732 return string; 739 return string;
733 } 740 }
734 741
735 } // namespace blink 742 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698