[scanner] Simplify special cases of ScanString

AdvanceUntil always starts at the character after c0_. This means that we
needed to handle first, causing some duplication. Instead of doing that, we can
also just not Advance() before AdvanceUntil, making c0_ a character that's
already handled.

Change-Id: I3e23f62a617b5d607579641fc19b12de4f179e8e
Reviewed-on: https://chromium-review.googlesource.com/c/1491512
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59897}
This commit is contained in:
Toon Verwaest 2019-02-27 12:58:08 +01:00 committed by Commit Bot
parent f0c90e2f9e
commit 78c7cf4bec

View File

@ -501,48 +501,42 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
Token::Value Scanner::ScanString() {
uc32 quote = c0_;
Advance(); // consume quote
next().literal_chars.Start();
while (true) {
if (V8_UNLIKELY(c0_ == kEndOfInput)) return Token::ILLEGAL;
if ((V8_UNLIKELY(static_cast<uint32_t>(c0_) >= kMaxAscii) &&
!unibrow::IsStringLiteralLineTerminator(c0_)) ||
!MayTerminateString(character_scan_flags[c0_])) {
AddLiteralChar(c0_);
AdvanceUntil([this](uc32 c0) {
if (V8_UNLIKELY(static_cast<uint32_t>(c0) > kMaxAscii)) {
if (V8_UNLIKELY(unibrow::IsStringLiteralLineTerminator(c0))) {
return true;
}
AddLiteralChar(c0);
return false;
AdvanceUntil([this](uc32 c0) {
if (V8_UNLIKELY(static_cast<uint32_t>(c0) > kMaxAscii)) {
if (V8_UNLIKELY(unibrow::IsStringLiteralLineTerminator(c0))) {
return true;
}
uint8_t char_flags = character_scan_flags[c0];
if (MayTerminateString(char_flags)) return true;
AddLiteralChar(c0);
return false;
});
}
if (c0_ == quote) {
Advance();
return Token::STRING;
}
if (c0_ == '\\') {
}
uint8_t char_flags = character_scan_flags[c0];
if (MayTerminateString(char_flags)) return true;
AddLiteralChar(c0);
return false;
});
while (c0_ == '\\') {
Advance();
// TODO(verwaest): Check whether we can remove the additional check.
if (V8_UNLIKELY(c0_ == kEndOfInput || !ScanEscape<false>())) {
return Token::ILLEGAL;
}
continue;
}
if (c0_ == quote) {
Advance();
return Token::STRING;
}
if (V8_UNLIKELY(c0_ == kEndOfInput ||
unibrow::IsStringLiteralLineTerminator(c0_))) {
return Token::ILLEGAL;
}
DCHECK_NE(quote, c0_);
DCHECK((c0_ == '\'' || c0_ == '"'));
AddLiteralCharAdvance();
AddLiteralChar(c0_);
}
}