Index: src/parsing/scanner.h |
diff --git a/src/parsing/scanner.h b/src/parsing/scanner.h |
index 63324c9bc6cc4a07eafdd86f9e625a485b714e3e..075b9ca6b2ba0c1d9468e7eef7e3598c85a5cd36 100644 |
--- a/src/parsing/scanner.h |
+++ b/src/parsing/scanner.h |
@@ -353,36 +353,16 @@ class Scanner { |
~LiteralBuffer() { backing_store_.Dispose(); } |
INLINE(void AddChar(char code_unit)) { |
- if (position_ >= backing_store_.length()) ExpandBuffer(); |
- DCHECK(is_one_byte_); |
DCHECK(IsValidAscii(code_unit)); |
- backing_store_[position_] = static_cast<byte>(code_unit); |
- position_ += kOneByteSize; |
- return; |
+ AddOneByteChar(static_cast<byte>(code_unit)); |
} |
INLINE(void AddChar(uc32 code_unit)) { |
- 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; |
- position_ += kUC16Size; |
+ if (is_one_byte_ && |
+ code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) { |
+ AddOneByteChar(static_cast<byte>(code_unit)); |
} else { |
- *reinterpret_cast<uint16_t*>(&backing_store_[position_]) = |
- unibrow::Utf16::LeadSurrogate(code_unit); |
- position_ += kUC16Size; |
- if (position_ >= backing_store_.length()) ExpandBuffer(); |
- *reinterpret_cast<uint16_t*>(&backing_store_[position_]) = |
- unibrow::Utf16::TrailSurrogate(code_unit); |
- position_ += kUC16Size; |
+ AddCharSlow(code_unit); |
} |
} |
@@ -434,43 +414,18 @@ class Scanner { |
return iscntrl(code_unit) || isprint(code_unit); |
} |
- inline int NewCapacity(int min_capacity) { |
- int capacity = Max(min_capacity, backing_store_.length()); |
- int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth); |
- return new_capacity; |
- } |
- |
- void ExpandBuffer() { |
- Vector<byte> new_store = Vector<byte>::New(NewCapacity(kInitialCapacity)); |
- MemCopy(new_store.start(), backing_store_.start(), position_); |
- backing_store_.Dispose(); |
- backing_store_ = new_store; |
- } |
- |
- void ConvertToTwoByte() { |
+ INLINE(void AddOneByteChar(byte one_byte_char)) { |
DCHECK(is_one_byte_); |
- Vector<byte> new_store; |
- int new_content_size = position_ * kUC16Size; |
- if (new_content_size >= backing_store_.length()) { |
- // Ensure room for all currently read code units as UC16 as well |
- // as the code unit about to be stored. |
- new_store = Vector<byte>::New(NewCapacity(new_content_size)); |
- } else { |
- new_store = backing_store_; |
- } |
- uint8_t* src = backing_store_.start(); |
- uint16_t* dst = reinterpret_cast<uint16_t*>(new_store.start()); |
- for (int i = position_ - 1; i >= 0; i--) { |
- dst[i] = src[i]; |
- } |
- if (new_store.start() != backing_store_.start()) { |
- backing_store_.Dispose(); |
- backing_store_ = new_store; |
- } |
- position_ = new_content_size; |
- is_one_byte_ = false; |
+ if (position_ >= backing_store_.length()) ExpandBuffer(); |
+ backing_store_[position_] = one_byte_char; |
+ position_ += kOneByteSize; |
} |
+ void AddCharSlow(uc32 code_unit); |
+ int NewCapacity(int min_capacity); |
+ void ExpandBuffer(); |
+ void ConvertToTwoByte(); |
+ |
bool is_one_byte_; |
int position_; |
Vector<byte> backing_store_; |