[scanner] Replace AddCharSlow with more explicit AddTwoByteChar and only check to convert once
Change-Id: I0d23484d9a48a73575ca158b07b7ed1b83d4029e Reviewed-on: https://chromium-review.googlesource.com/1172774 Reviewed-by: Camillo Bruni <cbruni@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/master@{#55095}
This commit is contained in:
parent
3b0f8243d0
commit
6772dc5c4a
@ -103,16 +103,9 @@ void Scanner::LiteralBuffer::ConvertToTwoByte() {
|
||||
is_one_byte_ = false;
|
||||
}
|
||||
|
||||
void Scanner::LiteralBuffer::AddCharSlow(uc32 code_unit) {
|
||||
void Scanner::LiteralBuffer::AddTwoByteChar(uc32 code_unit) {
|
||||
DCHECK(!is_one_byte_);
|
||||
if (position_ >= backing_store_.length()) ExpandBuffer();
|
||||
if (is_one_byte_) {
|
||||
if (code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) {
|
||||
backing_store_[position_] = static_cast<byte>(code_unit);
|
||||
position_ += kOneByteSize;
|
||||
return;
|
||||
}
|
||||
ConvertToTwoByte();
|
||||
}
|
||||
if (code_unit <=
|
||||
static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)) {
|
||||
*reinterpret_cast<uint16_t*>(&backing_store_[position_]) = code_unit;
|
||||
|
@ -280,12 +280,14 @@ class Scanner {
|
||||
}
|
||||
|
||||
V8_INLINE void AddChar(uc32 code_unit) {
|
||||
if (is_one_byte_ &&
|
||||
code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) {
|
||||
AddOneByteChar(static_cast<byte>(code_unit));
|
||||
} else {
|
||||
AddCharSlow(code_unit);
|
||||
if (is_one_byte_) {
|
||||
if (code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) {
|
||||
AddOneByteChar(static_cast<byte>(code_unit));
|
||||
return;
|
||||
}
|
||||
ConvertToTwoByte();
|
||||
}
|
||||
AddTwoByteChar(code_unit);
|
||||
}
|
||||
|
||||
bool is_one_byte() const { return is_one_byte_; }
|
||||
@ -339,7 +341,7 @@ class Scanner {
|
||||
position_ += kOneByteSize;
|
||||
}
|
||||
|
||||
void AddCharSlow(uc32 code_unit);
|
||||
void AddTwoByteChar(uc32 code_unit);
|
||||
int NewCapacity(int min_capacity);
|
||||
void ExpandBuffer();
|
||||
void ConvertToTwoByte();
|
||||
|
Loading…
Reference in New Issue
Block a user