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

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

Issue 2099683003: Optimize whitespace skipping in the CSSParser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase. Created 4 years, 5 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/CSSTokenizerInputStream.h ('k') | no next file » | 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/CSSTokenizerInputStream.h" 5 #include "core/css/parser/CSSTokenizerInputStream.h"
6 6
7 #include "core/html/parser/HTMLParserIdioms.h"
7 #include "core/html/parser/InputStreamPreprocessor.h" 8 #include "core/html/parser/InputStreamPreprocessor.h"
8 #include "wtf/text/StringToNumber.h" 9 #include "wtf/text/StringToNumber.h"
9 10
10 namespace blink { 11 namespace blink {
11 12
12 CSSTokenizerInputStream::CSSTokenizerInputStream(String input) 13 CSSTokenizerInputStream::CSSTokenizerInputStream(String input)
13 : m_offset(0) 14 : m_offset(0)
14 , m_stringLength(input.length()) 15 , m_stringLength(input.length())
15 , m_string(input.impl()) 16 , m_string(input.impl())
16 { 17 {
17 } 18 }
18 19
19 UChar CSSTokenizerInputStream::peek(unsigned lookaheadOffset) 20 UChar CSSTokenizerInputStream::peek(unsigned lookaheadOffset)
20 { 21 {
21 if ((m_offset + lookaheadOffset) >= m_stringLength) 22 if ((m_offset + lookaheadOffset) >= m_stringLength)
22 return kEndOfFileMarker; 23 return kEndOfFileMarker;
23 UChar result = (*m_string)[m_offset + lookaheadOffset]; 24 UChar result = (*m_string)[m_offset + lookaheadOffset];
24 return result ? result : 0xFFFD; 25 return result ? result : 0xFFFD;
25 } 26 }
26 27
27 void CSSTokenizerInputStream::pushBack(UChar cc) 28 void CSSTokenizerInputStream::pushBack(UChar cc)
28 { 29 {
29 --m_offset; 30 --m_offset;
30 ASSERT(nextInputChar() == cc); 31 ASSERT(nextInputChar() == cc);
31 } 32 }
32 33
34 void CSSTokenizerInputStream::advanceUntilNonWhitespace()
35 {
36 // Using HTML space here rather than CSS space since we don't do preprocessi ng
37 if (m_string->is8Bit()) {
38 const LChar* characters = m_string->characters8();
39 while (m_offset < m_stringLength && isHTMLSpace(characters[m_offset]))
40 ++m_offset;
41 } else {
42 const UChar* characters = m_string->characters16();
43 while (m_offset < m_stringLength && isHTMLSpace(characters[m_offset]))
44 ++m_offset;
45 }
46 }
47
33 double CSSTokenizerInputStream::getDouble(unsigned start, unsigned end) 48 double CSSTokenizerInputStream::getDouble(unsigned start, unsigned end)
34 { 49 {
35 ASSERT(start <= end && ((m_offset + end) <= m_stringLength)); 50 ASSERT(start <= end && ((m_offset + end) <= m_stringLength));
36 bool isResultOK = false; 51 bool isResultOK = false;
37 double result = 0.0; 52 double result = 0.0;
38 if (start < end) { 53 if (start < end) {
39 if (m_string->is8Bit()) 54 if (m_string->is8Bit())
40 result = charactersToDouble(m_string->characters8() + m_offset + sta rt, end - start, &isResultOK); 55 result = charactersToDouble(m_string->characters8() + m_offset + sta rt, end - start, &isResultOK);
41 else 56 else
42 result = charactersToDouble(m_string->characters16() + m_offset + st art, end - start, &isResultOK); 57 result = charactersToDouble(m_string->characters16() + m_offset + st art, end - start, &isResultOK);
43 } 58 }
44 // FIXME: It looks like callers ensure we have a valid number 59 // FIXME: It looks like callers ensure we have a valid number
45 return isResultOK ? result : 0.0; 60 return isResultOK ? result : 0.0;
46 } 61 }
47 62
48 StringView CSSTokenizerInputStream::rangeAt(unsigned start, unsigned length) con st 63 StringView CSSTokenizerInputStream::rangeAt(unsigned start, unsigned length) con st
49 { 64 {
50 ASSERT(start + length <= m_stringLength); 65 ASSERT(start + length <= m_stringLength);
51 return StringView(m_string.get(), start, length); 66 return StringView(m_string.get(), start, length);
52 } 67 }
53 68
54 } // namespace blink 69 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSTokenizerInputStream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698