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

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

Issue 2282303002: [test] lazily parse css style rules
Patch Set: use string pool Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSTokenizer.h ('k') | tools/run-perf-test.cfg » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
22 { 21 {
23 // According to the spec, we should perform preprocessing here. 22 // According to the spec, we should perform preprocessing here.
24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing 23 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing
25 // 24 //
26 // However, we can skip this step since: 25 // However, we can skip this step since:
27 // * We're using HTML spaces (which accept \r and \f as a valid white space) 26 // * We're using HTML spaces (which accept \r and \f as a valid white space)
28 // * Do not count white spaces 27 // * Do not count white spaces
29 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters 28 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters
30 29
31 if (string.isEmpty()) 30 if (string.isEmpty())
32 return; 31 return;
32 storeString(string);
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)
52 { 51 {
53 if (string.isEmpty()) 52 if (string.isEmpty())
54 return; 53 return;
54 storeString(string);
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();
62 if (token.type() == EOFToken) 62 if (token.type() == EOFToken)
63 break; 63 break;
64 if (token.type() == CommentToken) { 64 if (token.type() == CommentToken) {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return areIdentifier; 726 return areIdentifier;
727 } 727 }
728 728
729 StringView CSSTokenizer::registerString(const String& string) 729 StringView CSSTokenizer::registerString(const String& string)
730 { 730 {
731 m_scope.storeString(string); 731 m_scope.storeString(string);
732 return string; 732 return string;
733 } 733 }
734 734
735 } // namespace blink 735 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSTokenizer.h ('k') | tools/run-perf-test.cfg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698