Commit 84b36933 authored by verwaest's avatar verwaest Committed by Commit bot

Speed up parsing of smis

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26956}
parent a6f5fca5
...@@ -694,6 +694,10 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, ...@@ -694,6 +694,10 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
return factory->NewBooleanLiteral(true, pos); return factory->NewBooleanLiteral(true, pos);
case Token::FALSE_LITERAL: case Token::FALSE_LITERAL:
return factory->NewBooleanLiteral(false, pos); return factory->NewBooleanLiteral(false, pos);
case Token::SMI: {
int value = scanner->smi_value();
return factory->NewSmiLiteral(value, pos);
}
case Token::NUMBER: { case Token::NUMBER: {
double value = scanner->DoubleValue(); double value = scanner->DoubleValue();
return factory->NewNumberLiteral(value, pos); return factory->NewNumberLiteral(value, pos);
......
...@@ -1688,6 +1688,7 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { ...@@ -1688,6 +1688,7 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
switch (token) { switch (token) {
case Token::EOS: case Token::EOS:
return ReportMessageAt(source_location, "unexpected_eos"); return ReportMessageAt(source_location, "unexpected_eos");
case Token::SMI:
case Token::NUMBER: case Token::NUMBER:
return ReportMessageAt(source_location, "unexpected_token_number"); return ReportMessageAt(source_location, "unexpected_token_number");
case Token::STRING: case Token::STRING:
...@@ -1874,6 +1875,7 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) { ...@@ -1874,6 +1875,7 @@ ParserBase<Traits>::ParsePrimaryExpression(bool* ok) {
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
case Token::TRUE_LITERAL: case Token::TRUE_LITERAL:
case Token::FALSE_LITERAL: case Token::FALSE_LITERAL:
case Token::SMI:
case Token::NUMBER: case Token::NUMBER:
Next(); Next();
result = result =
...@@ -2055,6 +2057,11 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( ...@@ -2055,6 +2057,11 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
*name = this->GetSymbol(scanner()); *name = this->GetSymbol(scanner());
break; break;
case Token::SMI:
Consume(Token::SMI);
*name = this->GetNumberAsSymbol(scanner());
break;
case Token::NUMBER: case Token::NUMBER:
Consume(Token::NUMBER); Consume(Token::NUMBER);
*name = this->GetNumberAsSymbol(scanner()); *name = this->GetNumberAsSymbol(scanner());
...@@ -3069,7 +3076,7 @@ void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( ...@@ -3069,7 +3076,7 @@ void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
DCHECK(!is_static); DCHECK(!is_static);
DCHECK(!is_generator || type == kMethodProperty); DCHECK(!is_generator || type == kMethodProperty);
if (property == Token::NUMBER) return; if (property == Token::SMI || property == Token::NUMBER) return;
if (type == kValueProperty && IsProto()) { if (type == kValueProperty && IsProto()) {
if (has_seen_proto_) { if (has_seen_proto_) {
...@@ -3089,7 +3096,7 @@ void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( ...@@ -3089,7 +3096,7 @@ void ParserBase<Traits>::ClassLiteralChecker::CheckProperty(
bool* ok) { bool* ok) {
DCHECK(type == kMethodProperty || type == kAccessorProperty); DCHECK(type == kMethodProperty || type == kAccessorProperty);
if (property == Token::NUMBER) return; if (property == Token::SMI || property == Token::NUMBER) return;
if (is_static) { if (is_static) {
if (IsPrototype()) { if (IsPrototype()) {
......
...@@ -913,6 +913,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -913,6 +913,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL;
LiteralScope literal(this); LiteralScope literal(this);
bool at_start = !seen_period;
if (seen_period) { if (seen_period) {
// we have already seen a decimal point of the float // we have already seen a decimal point of the float
AddLiteralChar('.'); AddLiteralChar('.');
...@@ -962,6 +963,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -962,6 +963,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
kind = IMPLICIT_OCTAL; kind = IMPLICIT_OCTAL;
while (true) { while (true) {
if (c0_ == '8' || c0_ == '9') { if (c0_ == '8' || c0_ == '9') {
at_start = false;
kind = DECIMAL; kind = DECIMAL;
break; break;
} }
...@@ -977,6 +979,21 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -977,6 +979,21 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
// Parse decimal digits and allow trailing fractional part. // Parse decimal digits and allow trailing fractional part.
if (kind == DECIMAL) { if (kind == DECIMAL) {
if (at_start) {
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;
literal.Complete();
return Token::SMI;
}
}
ScanDecimalDigits(); // optional ScanDecimalDigits(); // optional
if (c0_ == '.') { if (c0_ == '.') {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
......
...@@ -436,6 +436,9 @@ class Scanner { ...@@ -436,6 +436,9 @@ class Scanner {
Location octal_position() const { return octal_pos_; } Location octal_position() const { return octal_pos_; }
void clear_octal_position() { octal_pos_ = Location::invalid(); } 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 // Seek forward to the given position. This operation does not
// work in general, for instance when there are pushed back // work in general, for instance when there are pushed back
// characters, but works for seeking forward until simple delimiter // characters, but works for seeking forward until simple delimiter
...@@ -722,6 +725,9 @@ class Scanner { ...@@ -722,6 +725,9 @@ class Scanner {
// Start position of the octal literal last scanned. // Start position of the octal literal last scanned.
Location octal_pos_; 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. // One Unicode character look-ahead; c0_ < 0 at the end of the input.
uc32 c0_; uc32 c0_;
......
...@@ -40,7 +40,7 @@ namespace internal { ...@@ -40,7 +40,7 @@ namespace internal {
T(COLON, ":", 0) \ T(COLON, ":", 0) \
T(SEMICOLON, ";", 0) \ T(SEMICOLON, ";", 0) \
T(PERIOD, ".", 0) \ T(PERIOD, ".", 0) \
T(ELLIPSIS, "...", 0) \ T(ELLIPSIS, "...", 0) \
T(CONDITIONAL, "?", 3) \ T(CONDITIONAL, "?", 3) \
T(INC, "++", 0) \ T(INC, "++", 0) \
T(DEC, "--", 0) \ T(DEC, "--", 0) \
...@@ -142,6 +142,7 @@ namespace internal { ...@@ -142,6 +142,7 @@ namespace internal {
K(TRUE_LITERAL, "true", 0) \ K(TRUE_LITERAL, "true", 0) \
K(FALSE_LITERAL, "false", 0) \ K(FALSE_LITERAL, "false", 0) \
T(NUMBER, NULL, 0) \ T(NUMBER, NULL, 0) \
T(SMI, NULL, 0) \
T(STRING, NULL, 0) \ T(STRING, NULL, 0) \
\ \
/* Identifiers (not keywords or future reserved words). */ \ /* Identifiers (not keywords or future reserved words). */ \
......
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