Commit bfc9eb2e authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[scanner] Micro-optimize AdvanceUntil

Replace std::find_if in AdvanceUntil with a manual loop, which can
then return early, skipping the branch comparing to buffer_end_.

Change-Id: If49ed3667877751fcb0103a742750f03e5bd50db
Reviewed-on: https://chromium-review.googlesource.com/c/1411351Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58846}
parent 3c34f1a5
......@@ -71,21 +71,18 @@ class Utf16CharacterStream {
template <typename FunctionType>
V8_INLINE uc32 AdvanceUntil(FunctionType check) {
while (true) {
auto next_cursor_pos =
std::find_if(buffer_cursor_, buffer_end_, [&check](uint16_t raw_c0_) {
uc32 c0_ = static_cast<uc32>(raw_c0_);
return check(c0_);
});
if (next_cursor_pos == buffer_end_) {
buffer_cursor_ = buffer_end_;
if (!ReadBlockChecked()) {
for (; buffer_cursor_ < buffer_end_; ++buffer_cursor_) {
uc32 c0_ = static_cast<uc32>(*buffer_cursor_);
if (check(c0_)) {
buffer_cursor_++;
return kEndOfInput;
return c0_;
}
} else {
buffer_cursor_ = next_cursor_pos + 1;
return static_cast<uc32>(*next_cursor_pos);
}
DCHECK_EQ(buffer_cursor_, buffer_end_);
if (!ReadBlockChecked()) {
buffer_cursor_++;
return kEndOfInput;
}
}
}
......
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