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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSTokenizer.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
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
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return current; 114 return current;
115 } 115 }
116 116
117 void CSSTokenizer::consume(unsigned offset) 117 void CSSTokenizer::consume(unsigned offset)
118 { 118 {
119 m_input.advance(offset); 119 m_input.advance(offset);
120 } 120 }
121 121
122 CSSParserToken CSSTokenizer::whiteSpace(UChar cc) 122 CSSParserToken CSSTokenizer::whiteSpace(UChar cc)
123 { 123 {
124 consumeUntilNonWhitespace(); 124 m_input.advanceUntilNonWhitespace();
125 return CSSParserToken(WhitespaceToken); 125 return CSSParserToken(WhitespaceToken);
126 } 126 }
127 127
128 static bool popIfBlockMatches(Vector<CSSParserTokenType>& blockStack, CSSParserT okenType type) 128 static bool popIfBlockMatches(Vector<CSSParserTokenType>& blockStack, CSSParserT okenType type)
129 { 129 {
130 if (!blockStack.isEmpty() && blockStack.last() == type) { 130 if (!blockStack.isEmpty() && blockStack.last() == type) {
131 blockStack.removeLast(); 131 blockStack.removeLast();
132 return true; 132 return true;
133 } 133 }
134 return false; 134 return false;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 464 }
465 465
466 // http://dev.w3.org/csswg/css-syntax/#consume-ident-like-token 466 // http://dev.w3.org/csswg/css-syntax/#consume-ident-like-token
467 CSSParserToken CSSTokenizer::consumeIdentLikeToken() 467 CSSParserToken CSSTokenizer::consumeIdentLikeToken()
468 { 468 {
469 StringView name = consumeName(); 469 StringView name = consumeName();
470 if (consumeIfNext('(')) { 470 if (consumeIfNext('(')) {
471 if (equalIgnoringASCIICase(name, "url")) { 471 if (equalIgnoringASCIICase(name, "url")) {
472 // The spec is slightly different so as to avoid dropping whitespace 472 // The spec is slightly different so as to avoid dropping whitespace
473 // tokens, but they wouldn't be used and this is easier. 473 // tokens, but they wouldn't be used and this is easier.
474 consumeUntilNonWhitespace(); 474 m_input.advanceUntilNonWhitespace();
475 UChar next = m_input.nextInputChar(); 475 UChar next = m_input.nextInputChar();
476 if (next != '"' && next != '\'') 476 if (next != '"' && next != '\'')
477 return consumeUrlToken(); 477 return consumeUrlToken();
478 } 478 }
479 return blockStart(LeftParenthesisToken, FunctionToken, name); 479 return blockStart(LeftParenthesisToken, FunctionToken, name);
480 } 480 }
481 return CSSParserToken(IdentToken, name); 481 return CSSParserToken(IdentToken, name);
482 } 482 }
483 483
484 // http://dev.w3.org/csswg/css-syntax/#consume-a-string-token 484 // http://dev.w3.org/csswg/css-syntax/#consume-a-string-token
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 555
556 // http://dev.w3.org/csswg/css-syntax/#non-printable-code-point 556 // http://dev.w3.org/csswg/css-syntax/#non-printable-code-point
557 static bool isNonPrintableCodePoint(UChar cc) 557 static bool isNonPrintableCodePoint(UChar cc)
558 { 558 {
559 return (cc >= '\0' && cc <= '\x8') || cc == '\xb' || (cc >= '\xe' && cc <= ' \x1f') || cc == '\x7f'; 559 return (cc >= '\0' && cc <= '\x8') || cc == '\xb' || (cc >= '\xe' && cc <= ' \x1f') || cc == '\x7f';
560 } 560 }
561 561
562 // http://dev.w3.org/csswg/css-syntax/#consume-url-token 562 // http://dev.w3.org/csswg/css-syntax/#consume-url-token
563 CSSParserToken CSSTokenizer::consumeUrlToken() 563 CSSParserToken CSSTokenizer::consumeUrlToken()
564 { 564 {
565 consumeUntilNonWhitespace(); 565 m_input.advanceUntilNonWhitespace();
566 566
567 // URL tokens without escapes get handled without allocations 567 // URL tokens without escapes get handled without allocations
568 for (unsigned size = 0; ; size++) { 568 for (unsigned size = 0; ; size++) {
569 UChar cc = m_input.peekWithoutReplacement(size); 569 UChar cc = m_input.peekWithoutReplacement(size);
570 if (cc == ')') { 570 if (cc == ')') {
571 unsigned startOffset = m_input.offset(); 571 unsigned startOffset = m_input.offset();
572 m_input.advance(size + 1); 572 m_input.advance(size + 1);
573 return CSSParserToken(UrlToken, m_input.rangeAt(startOffset, size)); 573 return CSSParserToken(UrlToken, m_input.rangeAt(startOffset, size));
574 } 574 }
575 if (cc <= ' ' || cc == '\\' || cc == '"' || cc == '\'' || cc == '(' || c c == '\x7f') 575 if (cc <= ' ' || cc == '\\' || cc == '"' || cc == '\'' || cc == '(' || c c == '\x7f')
576 break; 576 break;
577 } 577 }
578 578
579 StringBuilder result; 579 StringBuilder result;
580 while (true) { 580 while (true) {
581 UChar cc = consume(); 581 UChar cc = consume();
582 if (cc == ')' || cc == kEndOfFileMarker) 582 if (cc == ')' || cc == kEndOfFileMarker)
583 return CSSParserToken(UrlToken, registerString(result.toString())); 583 return CSSParserToken(UrlToken, registerString(result.toString()));
584 584
585 if (isHTMLSpace(cc)) { 585 if (isHTMLSpace(cc)) {
586 consumeUntilNonWhitespace(); 586 m_input.advanceUntilNonWhitespace();
587 if (consumeIfNext(')') || m_input.nextInputChar() == kEndOfFileMarke r) 587 if (consumeIfNext(')') || m_input.nextInputChar() == kEndOfFileMarke r)
588 return CSSParserToken(UrlToken, registerString(result.toString() )); 588 return CSSParserToken(UrlToken, registerString(result.toString() ));
589 break; 589 break;
590 } 590 }
591 591
592 if (cc == '"' || cc == '\'' || cc == '(' || isNonPrintableCodePoint(cc)) 592 if (cc == '"' || cc == '\'' || cc == '(' || isNonPrintableCodePoint(cc))
593 break; 593 break;
594 594
595 if (cc == '\\') { 595 if (cc == '\\') {
596 if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) { 596 if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) {
(...skipping 15 matching lines...) Expand all
612 { 612 {
613 while (true) { 613 while (true) {
614 UChar cc = consume(); 614 UChar cc = consume();
615 if (cc == ')' || cc == kEndOfFileMarker) 615 if (cc == ')' || cc == kEndOfFileMarker)
616 return; 616 return;
617 if (twoCharsAreValidEscape(cc, m_input.nextInputChar())) 617 if (twoCharsAreValidEscape(cc, m_input.nextInputChar()))
618 consumeEscape(); 618 consumeEscape();
619 } 619 }
620 } 620 }
621 621
622 void CSSTokenizer::consumeUntilNonWhitespace()
623 {
624 // Using HTML space here rather than CSS space since we don't do preprocessi ng
625 while (isHTMLSpace<UChar>(m_input.nextInputChar()))
626 consume();
627 }
628
629 void CSSTokenizer::consumeSingleWhitespaceIfNext() 622 void CSSTokenizer::consumeSingleWhitespaceIfNext()
630 { 623 {
631 // We check for \r\n and HTML spaces since we don't do preprocessing 624 // We check for \r\n and HTML spaces since we don't do preprocessing
632 UChar c = m_input.nextInputChar(); 625 UChar c = m_input.nextInputChar();
633 if (c == '\r' && m_input.peek(1) == '\n') 626 if (c == '\r' && m_input.peek(1) == '\n')
634 consume(2); 627 consume(2);
635 else if (isHTMLSpace(c)) 628 else if (isHTMLSpace(c))
636 consume(); 629 consume();
637 } 630 }
638 631
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return areIdentifier; 765 return areIdentifier;
773 } 766 }
774 767
775 StringView CSSTokenizer::registerString(const String& string) 768 StringView CSSTokenizer::registerString(const String& string)
776 { 769 {
777 m_scope.storeString(string); 770 m_scope.storeString(string);
778 return string; 771 return string;
779 } 772 }
780 773
781 } // namespace blink 774 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698