Commit 85d9cd7e authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

[scanner] Split SkipWhiteSpace into fast and slow path

This places the hot part of SkipWhiteSpace in the header, allowing it to be
inlined, and leaves a slow path to handle the rest. This improves comment
scanning overall by ~10%.

Bug: v8:7926
Change-Id: I2e2ebbbae0d1af619b161397712fdf667d078884
Reviewed-on: https://chromium-review.googlesource.com/1150230
Commit-Queue: Florian Sattler <sattlerf@google.com>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54744}
parent ac226c08
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_PARSING_SCANNER_INL_H_
#define V8_PARSING_SCANNER_INL_H_
#include "src/parsing/scanner.h"
#include "src/unicode-cache-inl.h"
namespace v8 {
namespace internal {
V8_INLINE Token::Value Scanner::SkipWhiteSpace() {
int start_position = source_pos();
SkipWhiteSpaceImpl();
// If there is an HTML comment end '-->' at the beginning of a
// line (with only whitespace in front of it), we treat the rest
// of the line as a comment. This is in line with the way
// SpiderMonkey handles it.
if (c0_ != '-' || !has_line_terminator_before_next_) {
// Return whether or not we skipped any characters.
if (source_pos() == start_position) {
return Token::ILLEGAL;
}
return Token::WHITESPACE;
}
return TryToSkipHTMLCommentAndWhiteSpaces(start_position);
}
V8_INLINE void Scanner::SkipWhiteSpaceImpl() {
while (true) {
// We won't skip behind the end of input.
DCHECK(!unicode_cache_->IsWhiteSpace(kEndOfInput));
// Advance as long as character is a WhiteSpace or LineTerminator.
// Remember if the latter is the case.
if (unibrow::IsLineTerminator(c0_)) {
has_line_terminator_before_next_ = true;
} else if (!unicode_cache_->IsWhiteSpace(c0_)) {
break;
}
Advance();
}
}
} // namespace internal
} // namespace v8
#endif // V8_PARSING_SCANNER_INL_H_
......@@ -15,7 +15,7 @@
#include "src/conversions-inl.h"
#include "src/objects/bigint.h"
#include "src/parsing/duplicate-finder.h" // For Scanner::FindSymbol
#include "src/unicode-cache-inl.h"
#include "src/parsing/scanner-inl.h"
namespace v8 {
namespace internal {
......@@ -420,32 +420,13 @@ Token::Value Scanner::PeekAhead() {
return ret;
}
Token::Value Scanner::SkipWhiteSpace() {
int start_position = source_pos();
Token::Value Scanner::TryToSkipHTMLCommentAndWhiteSpaces(int start_position) {
while (true) {
while (true) {
// We won't skip behind the end of input.
DCHECK(!unicode_cache_->IsWhiteSpace(kEndOfInput));
// Advance as long as character is a WhiteSpace or LineTerminator.
// Remember if the latter is the case.
if (unibrow::IsLineTerminator(c0_)) {
has_line_terminator_before_next_ = true;
} else if (!unicode_cache_->IsWhiteSpace(c0_)) {
break;
}
Advance();
}
Advance();
// If there is an HTML comment end '-->' at the beginning of a
// line (with only whitespace in front of it), we treat the rest
// of the line as a comment. This is in line with the way
// SpiderMonkey handles it.
if (c0_ != '-' || !has_line_terminator_before_next_) break;
Advance();
// line, we treat the rest of the line as a comment. This is in line with
// the way SpiderMonkey handles it.
if (c0_ != '-') {
PushBack('-'); // undo Advance()
break;
......@@ -462,6 +443,12 @@ Token::Value Scanner::SkipWhiteSpace() {
if (token == Token::ILLEGAL) {
return token;
}
// Skip remaining whitespaces after the HTML comment.
SkipWhiteSpaceImpl();
// Only repeat loop if we find another HTML comment
if (c0_ != '-' || !has_line_terminator_before_next_) break;
}
// Return whether or not we skipped any characters.
......
......@@ -728,7 +728,9 @@ class Scanner {
// Scans a single JavaScript token.
void Scan();
Token::Value SkipWhiteSpace();
V8_INLINE Token::Value SkipWhiteSpace();
V8_INLINE void SkipWhiteSpaceImpl();
Token::Value TryToSkipHTMLCommentAndWhiteSpaces(int start_position);
Token::Value SkipSingleHTMLComment();
Token::Value SkipSingleLineComment();
Token::Value SkipSourceURLComment();
......
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