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

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

Issue 2315923002: Lazy Parse CSS (Closed)
Patch Set: plug leaks 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_stringPool(new Vector<String>)
Timothy Loh 2016/09/26 05:18:01 Let's lazily allocate this -- I don't think it'll
Charlie Harrison 2016/09/26 22:14:45 Great point. Done.
22 , m_string(string)
22 { 23 {
23 // According to the spec, we should perform preprocessing here. 24 // According to the spec, we should perform preprocessing here.
24 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing 25 // See: http://dev.w3.org/csswg/css-syntax/#input-preprocessing
25 // 26 //
26 // However, we can skip this step since: 27 // However, we can skip this step since:
27 // * We're using HTML spaces (which accept \r and \f as a valid white space) 28 // * We're using HTML spaces (which accept \r and \f as a valid white space)
28 // * Do not count white spaces 29 // * Do not count white spaces
29 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters 30 // * CSSTokenizerInputStream::nextInputChar() replaces NULLs for replacement characters
30 31
31 if (string.isEmpty()) 32 if (string.isEmpty())
32 return; 33 return;
33 34
34 // To avoid resizing we err on the side of reserving too much space. 35 // 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. 36 // Most strings we tokenize have about 3.5 to 5 characters per token.
36 m_tokens.reserveInitialCapacity(string.length() / 3); 37 m_tokens.reserveInitialCapacity(string.length() / 3);
37 38
38 CSSTokenizerInputStream input(string); 39 CSSTokenizerInputStream input(string);
39 CSSTokenizer tokenizer(input, *this); 40 CSSTokenizer tokenizer(input, *this);
40 while (true) { 41 while (true) {
41 CSSParserToken token = tokenizer.nextToken(); 42 CSSParserToken token = tokenizer.nextToken();
42 if (token.type() == CommentToken) 43 if (token.type() == CommentToken)
43 continue; 44 continue;
44 if (token.type() == EOFToken) 45 if (token.type() == EOFToken)
45 return; 46 return;
46 m_tokens.append(token); 47 m_tokens.append(token);
47 } 48 }
48 } 49 }
49 50
50 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp er) 51 CSSTokenizer::Scope::Scope(const String& string, CSSParserObserverWrapper& wrapp er)
51 : m_string(string) 52 : m_stringPool(new Vector<String>)
53 , m_string(string)
52 { 54 {
53 if (string.isEmpty()) 55 if (string.isEmpty())
54 return; 56 return;
55 57
56 CSSTokenizerInputStream input(string); 58 CSSTokenizerInputStream input(string);
57 CSSTokenizer tokenizer(input, *this); 59 CSSTokenizer tokenizer(input, *this);
58 60
59 unsigned offset = 0; 61 unsigned offset = 0;
60 while (true) { 62 while (true) {
61 CSSParserToken token = tokenizer.nextToken(); 63 CSSParserToken token = tokenizer.nextToken();
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return areIdentifier; 728 return areIdentifier;
727 } 729 }
728 730
729 StringView CSSTokenizer::registerString(const String& string) 731 StringView CSSTokenizer::registerString(const String& string)
730 { 732 {
731 m_scope.storeString(string); 733 m_scope.storeString(string);
732 return string; 734 return string;
733 } 735 }
734 736
735 } // namespace blink 737 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698