Commit c8f9d7ab authored by verwaest's avatar verwaest Committed by Commit bot

Speed up string scanning

BUG=

Review URL: https://codereview.chromium.org/975043002

Cr-Commit-Position: refs/heads/master@{#26997}
parent f6cd009e
...@@ -788,11 +788,31 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) { ...@@ -788,11 +788,31 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
} }
const int kMaxAscii = 127;
Token::Value Scanner::ScanString() { Token::Value Scanner::ScanString() {
uc32 quote = c0_; uc32 quote = c0_;
Advance(); // consume quote Advance<false, false>(); // consume quote
LiteralScope literal(this); LiteralScope literal(this);
while (true) {
if (c0_ > kMaxAscii) {
HandleLeadSurrogate();
break;
}
if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL;
if (c0_ == quote) {
literal.Complete();
Advance<false, false>();
return Token::STRING;
}
uc32 c = c0_;
if (c == '\\') break;
Advance<false, false>();
AddLiteralChar(c);
}
while (c0_ != quote && c0_ >= 0 while (c0_ != quote && c0_ >= 0
&& !unicode_cache_->IsLineTerminator(c0_)) { && !unicode_cache_->IsLineTerminator(c0_)) {
uc32 c = c0_; uc32 c = c0_;
...@@ -993,11 +1013,11 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -993,11 +1013,11 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
c0_ != '.' && c0_ != 'e' && c0_ != 'E') { c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
smi_value_ = value; smi_value_ = value;
literal.Complete(); literal.Complete();
HandleLeadSurrugate(); HandleLeadSurrogate();
return Token::SMI; return Token::SMI;
} }
HandleLeadSurrugate(); HandleLeadSurrogate();
} }
ScanDecimalDigits(); // optional ScanDecimalDigits(); // optional
...@@ -1217,11 +1237,11 @@ Token::Value Scanner::ScanIdentifierOrKeyword() { ...@@ -1217,11 +1237,11 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
Advance<false, false>(); Advance<false, false>();
AddLiteralChar(first_char); AddLiteralChar(first_char);
} }
if (c0_ <= 127 && c0_ != '\\') { if (c0_ <= kMaxAscii && c0_ != '\\') {
literal.Complete(); literal.Complete();
return Token::IDENTIFIER; return Token::IDENTIFIER;
} }
} else if (c0_ <= 127 && c0_ != '\\') { } else if (c0_ <= kMaxAscii && c0_ != '\\') {
// Only a-z+: could be a keyword or identifier. // Only a-z+: could be a keyword or identifier.
literal.Complete(); literal.Complete();
Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
...@@ -1230,7 +1250,7 @@ Token::Value Scanner::ScanIdentifierOrKeyword() { ...@@ -1230,7 +1250,7 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
harmony_classes_); harmony_classes_);
} }
HandleLeadSurrugate(); HandleLeadSurrogate();
} else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') {
do { do {
uc32 first_char = c0_; uc32 first_char = c0_;
...@@ -1238,12 +1258,12 @@ Token::Value Scanner::ScanIdentifierOrKeyword() { ...@@ -1238,12 +1258,12 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
AddLiteralChar(first_char); AddLiteralChar(first_char);
} while (IsAsciiIdentifier(c0_)); } while (IsAsciiIdentifier(c0_));
if (c0_ <= 127 && c0_ != '\\') { if (c0_ <= kMaxAscii && c0_ != '\\') {
literal.Complete(); literal.Complete();
return Token::IDENTIFIER; return Token::IDENTIFIER;
} }
HandleLeadSurrugate(); HandleLeadSurrogate();
} else if (c0_ == '\\') { } else if (c0_ == '\\') {
// Scan identifier start character. // Scan identifier start character.
uc32 c = ScanIdentifierUnicodeEscape(); uc32 c = ScanIdentifierUnicodeEscape();
......
...@@ -571,10 +571,10 @@ class Scanner { ...@@ -571,10 +571,10 @@ class Scanner {
AddRawLiteralChar(c0_); AddRawLiteralChar(c0_);
} }
c0_ = source_->Advance(); c0_ = source_->Advance();
if (check_surrogate) HandleLeadSurrugate(); if (check_surrogate) HandleLeadSurrogate();
} }
void HandleLeadSurrugate() { void HandleLeadSurrogate() {
if (unibrow::Utf16::IsLeadSurrogate(c0_)) { if (unibrow::Utf16::IsLeadSurrogate(c0_)) {
uc32 c1 = source_->Advance(); uc32 c1 = source_->Advance();
if (!unibrow::Utf16::IsTrailSurrogate(c1)) { if (!unibrow::Utf16::IsTrailSurrogate(c1)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment