Reviewers: Yang,
Message:
PTAL
Description:
Speed up parsing of smis
BUG=
Please review this at https://codereview.chromium.org/974783003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+31, -3 lines):
M src/parser.cc
M src/preparser.h
M src/scanner.h
M src/scanner.cc
M src/token.h
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
aa6ee8ccb6c67a3d210a39b18e97a31f9808ea32..b82b652ce140b0439bc8471e333106360c3db4e0
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -694,6 +694,10 @@ Literal*
ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
return factory->NewBooleanLiteral(true, pos);
case Token::FALSE_LITERAL:
return factory->NewBooleanLiteral(false, pos);
+ case Token::SMI: {
+ int value = scanner->smi_value();
+ return factory->NewSmiLiteral(value, pos);
+ }
case Token::NUMBER: {
double value = scanner->DoubleValue();
return factory->NewNumberLiteral(value, pos);
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
64f456b2d7d808cb10a56986ad667f7c0f53892c..32bbfd86f4621d93a44bc9508c20df441998c5a0
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -1688,6 +1688,7 @@ void
ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
switch (token) {
case Token::EOS:
return ReportMessageAt(source_location, "unexpected_eos");
+ case Token::SMI:
case Token::NUMBER:
return ReportMessageAt(source_location, "unexpected_token_number");
case Token::STRING:
@@ -1874,6 +1875,7 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) {
case Token::NULL_LITERAL:
case Token::TRUE_LITERAL:
case Token::FALSE_LITERAL:
+ case Token::SMI:
case Token::NUMBER:
Next();
result =
@@ -2055,6 +2057,7 @@ typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParsePropertyName(
*name = this->GetSymbol(scanner());
break;
+ case Token::SMI:
case Token::NUMBER:
Consume(Token::NUMBER);
*name = this->GetNumberAsSymbol(scanner());
@@ -3069,7 +3072,7 @@ void
ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
DCHECK(!is_static);
DCHECK(!is_generator || type == kMethodProperty);
- if (property == Token::NUMBER) return;
+ if (property == Token::SMI || property == Token::NUMBER) return;
if (type == kValueProperty && IsProto()) {
if (has_seen_proto_) {
@@ -3089,7 +3092,7 @@ void
ParserBase<Traits>::ClassLiteralChecker::CheckProperty(
bool* ok) {
DCHECK(type == kMethodProperty || type == kAccessorProperty);
- if (property == Token::NUMBER) return;
+ if (property == Token::SMI || property == Token::NUMBER) return;
if (is_static) {
if (IsPrototype()) {
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index
de1b8e8b7202d211b297e8ca5737fb8f411299ed..46cb5a5176b4db3c1d5830b7bfefa76d4cfa51c1
100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -977,6 +977,20 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
// Parse decimal digits and allow trailing fractional part.
if (kind == DECIMAL) {
+ if (!seen_period) {
+ int value = 0;
+ while (IsDecimalDigit(c0_)) {
+ value = 10 * value + (c0_ - '0');
+ AddLiteralCharAdvance();
+ }
+
+ if (next_.literal_chars->one_byte_literal().length() < 10 &&
+ c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
+ smi_value_ = value;
+ return Token::SMI;
+ }
+ }
+
ScanDecimalDigits(); // optional
if (c0_ == '.') {
AddLiteralCharAdvance();
Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index
86a0098f86c0b4c97b4958148c4f6d27f04ce9b8..0e3013f4b8f7d6a910dcb9e26042b40238c1aaa2
100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -436,6 +436,9 @@ class Scanner {
Location octal_position() const { return octal_pos_; }
void clear_octal_position() { octal_pos_ = Location::invalid(); }
+ // Returns the value of the last smi that was scanned.
+ int smi_value() const { return smi_value_; }
+
// Seek forward to the given position. This operation does not
// work in general, for instance when there are pushed back
// characters, but works for seeking forward until simple delimiter
@@ -722,6 +725,9 @@ class Scanner {
// Start position of the octal literal last scanned.
Location octal_pos_;
+ // Value of the last smi that was scanned.
+ int smi_value_;
+
// One Unicode character look-ahead; c0_ < 0 at the end of the input.
uc32 c0_;
Index: src/token.h
diff --git a/src/token.h b/src/token.h
index
0f46b118cd58035444d2338896bec214b3cc5d63..cc7e9f8cbdc0b0a55c9429d3a425514897cff0ab
100644
--- a/src/token.h
+++ b/src/token.h
@@ -40,7 +40,7 @@ namespace internal {
T(COLON, ":", 0) \
T(SEMICOLON, ";", 0) \
T(PERIOD, ".", 0) \
- T(ELLIPSIS, "...", 0) \
+ T(ELLIPSIS, "...", 0) \
T(CONDITIONAL, "?", 3) \
T(INC, "++", 0) \
T(DEC, "--", 0) \
@@ -142,6 +142,7 @@ namespace internal {
K(TRUE_LITERAL, "true", 0) \
K(FALSE_LITERAL, "false", 0) \
T(NUMBER, NULL, 0) \
+ T(SMI, NULL, 0) \
T(STRING, NULL, 0) \
\
/* Identifiers (not keywords or future reserved words). */ \
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.