[scanner] Faster SkipMultiLineComment by avoiding a copy.

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

BUG=v8:7926

Change-Id: I0b62f711674beac8c81a25dd566a5ed0d681948b
Reviewed-on: https://chromium-review.googlesource.com/1148456
Commit-Queue: Florian Sattler <sattlerf@google.com>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54657}
This commit is contained in:
Florian Sattler 2018-07-24 17:09:44 +02:00 committed by Commit Bot
parent d324382e1c
commit 9c4200b2e9

View File

@ -555,28 +555,30 @@ 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;
}
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 (ch == '*' && c0_ == '/') {
if (c0_ == '/') {
c0_ = ' ';
return Token::WHITESPACE;
}
}
Advance();
}
// Unterminated multi-line comment.
return Token::ILLEGAL;