Speed up parsing of smis

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26956}
This commit is contained in:
verwaest 2015-03-03 03:04:49 -08:00 committed by Commit bot
parent a6f5fca5e6
commit 84b36933c5
5 changed files with 38 additions and 3 deletions

View File

@ -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);

View File

@ -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,11 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
*name = this->GetSymbol(scanner());
break;
case Token::SMI:
Consume(Token::SMI);
*name = this->GetNumberAsSymbol(scanner());
break;
case Token::NUMBER:
Consume(Token::NUMBER);
*name = this->GetNumberAsSymbol(scanner());
@ -3069,7 +3076,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 +3096,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()) {

View File

@ -913,6 +913,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL;
LiteralScope literal(this);
bool at_start = !seen_period;
if (seen_period) {
// we have already seen a decimal point of the float
AddLiteralChar('.');
@ -962,6 +963,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
kind = IMPLICIT_OCTAL;
while (true) {
if (c0_ == '8' || c0_ == '9') {
at_start = false;
kind = DECIMAL;
break;
}
@ -977,6 +979,21 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
// Parse decimal digits and allow trailing fractional part.
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
if (c0_ == '.') {
AddLiteralCharAdvance();

View File

@ -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_;

View File

@ -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). */ \