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

Unified Diff: src/scanner.cc

Issue 969353003: Speed up identifier, keyword and smi parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use char predicates Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index 1d41cb59312039b22954a562d9328eddff6b75e6..a141f8aa0208a9144a0732071a6db307c621a5cd 100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -983,15 +983,21 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
int value = 0;
while (IsDecimalDigit(c0_)) {
value = 10 * value + (c0_ - '0');
- AddLiteralCharAdvance();
+
+ uc32 first_char = c0_;
+ Advance<false, false>();
+ AddLiteralChar(first_char);
}
if (next_.literal_chars->one_byte_literal().length() < 10 &&
c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
smi_value_ = value;
literal.Complete();
+ HandleLeadSurrugate();
+
return Token::SMI;
}
+ HandleLeadSurrugate();
}
ScanDecimalDigits(); // optional
@@ -1193,8 +1199,53 @@ bool Scanner::IdentifierIsFutureStrictReserved(
Token::Value Scanner::ScanIdentifierOrKeyword() {
DCHECK(unicode_cache_->IsIdentifierStart(c0_));
LiteralScope literal(this);
- // Scan identifier start character.
- if (c0_ == '\\') {
+ if (IsInRange(c0_, 'a', 'z')) {
+ do {
+ uc32 first_char = c0_;
+ Advance<false, false>();
+ AddLiteralChar(first_char);
+ } while (IsInRange(c0_, 'a', 'z'));
+
+ if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' ||
+ c0_ == '$') {
+ // Identifier starting with lowercase.
+ uc32 first_char = c0_;
+ Advance<false, false>();
+ AddLiteralChar(first_char);
+ while (IsAsciiIdentifier(c0_)) {
+ uc32 first_char = c0_;
+ Advance<false, false>();
+ AddLiteralChar(first_char);
+ }
+ if (c0_ <= 127 && c0_ != '\\') {
+ literal.Complete();
+ return Token::IDENTIFIER;
+ }
+ } else if (c0_ <= 127 && c0_ != '\\') {
+ // Only a-z+: could be a keyword or identifier.
+ literal.Complete();
+ Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
+ return KeywordOrIdentifierToken(chars.start(), chars.length(),
+ harmony_scoping_, harmony_modules_,
+ harmony_classes_);
+ }
+
+ HandleLeadSurrugate();
+ } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') {
+ do {
+ uc32 first_char = c0_;
+ Advance<false, false>();
+ AddLiteralChar(first_char);
+ } while (IsAsciiIdentifier(c0_));
+
+ if (c0_ <= 127 && c0_ != '\\') {
+ literal.Complete();
+ return Token::IDENTIFIER;
+ }
+
+ HandleLeadSurrugate();
+ } else if (c0_ == '\\') {
+ // Scan identifier start character.
uc32 c = ScanIdentifierUnicodeEscape();
// Only allow legal identifier start characters.
if (c < 0 ||
@@ -1204,12 +1255,12 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
}
AddLiteralChar(c);
return ScanIdentifierSuffix(&literal);
+ } else {
+ uc32 first_char = c0_;
+ Advance();
+ AddLiteralChar(first_char);
}
- uc32 first_char = c0_;
- Advance();
- AddLiteralChar(first_char);
-
// Scan the rest of the identifier characters.
while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) {
if (c0_ != '\\') {
@@ -1232,7 +1283,6 @@ Token::Value Scanner::ScanIdentifierOrKeyword() {
harmony_modules_,
harmony_classes_);
}
-
return Token::IDENTIFIER;
}
« no previous file with comments | « src/scanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698