Commit e67f89b5 authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

[scanner] Faster SkipMultiLineComment by avoiding a copy.

Avoid copying the last character to a local variable, by checking the parsing
state in a different order.

BUG=v8:7926

Change-Id: Ifb722dd3864737dc66d8e0885adbeba1376a059e
Reviewed-on: https://chromium-review.googlesource.com/1148569Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Florian Sattler <sattlerf@google.com>
Cr-Commit-Position: refs/heads/master@{#54680}
parent ad55d888
......@@ -181,6 +181,9 @@ Scanner::Scanner(UnicodeCache* unicode_cache)
: unicode_cache_(unicode_cache),
octal_pos_(Location::invalid()),
octal_message_(MessageTemplate::kNone),
has_line_terminator_before_next_(false),
has_multiline_comment_before_next_(false),
has_line_terminator_after_next_(false),
found_html_comment_(false),
allow_harmony_bigint_(false),
allow_harmony_numeric_separator_(false) {}
......@@ -555,27 +558,29 @@ void Scanner::TryToParseSourceURLComment() {
}
}
Token::Value Scanner::SkipMultiLineComment() {
DCHECK_EQ(c0_, '*');
Advance();
while (c0_ != kEndOfInput) {
uc32 ch = c0_;
Advance();
DCHECK(!unibrow::IsLineTerminator(kEndOfInput));
if (unibrow::IsLineTerminator(ch)) {
if (!has_multiline_comment_before_next_ && unibrow::IsLineTerminator(c0_)) {
// Following ECMA-262, section 7.4, a comment containing
// a newline will make the comment count as a line-terminator.
has_multiline_comment_before_next_ = true;
}
// If we have reached the end of the multi-line comment, we
// consume the '/' and insert a whitespace. This way all
// multi-line comments are treated as whitespace.
if (ch == '*' && c0_ == '/') {
c0_ = ' ';
return Token::WHITESPACE;
while (V8_UNLIKELY(c0_ == '*')) {
Advance();
// If we have reached the end of the multi-line comment, we
// consume the '/' and insert a whitespace. This way all
// multi-line comments are treated as whitespace.
if (c0_ == '/') {
c0_ = ' ';
return Token::WHITESPACE;
}
}
Advance();
}
// Unterminated multi-line comment.
......
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