Commit 778cf612 authored by vogelheim's avatar vogelheim Committed by Commit bot

[parser] Reduce excessive inlining.

The inlining does not seem to actually improve performance, and hence outlining makes the code a bit more readable.

Performance + binary size appear to be at least as good as with inlining. On gcc I get several 10kBs savings in binary size, but only ~100B on clang. In no case have I observed a performance regression.

R=marja@chromium.org
BUG=v8:3437

Review-Url: https://codereview.chromium.org/2611993002
Cr-Commit-Position: refs/heads/master@{#42276}
parent 75a2fce3
...@@ -26,6 +26,68 @@ Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const { ...@@ -26,6 +26,68 @@ Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const {
return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); return isolate->factory()->InternalizeTwoByteString(two_byte_literal());
} }
int Scanner::LiteralBuffer::NewCapacity(int min_capacity) {
int capacity = Max(min_capacity, backing_store_.length());
int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth);
return new_capacity;
}
void Scanner::LiteralBuffer::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 Scanner::LiteralBuffer::ConvertToTwoByte() {
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;
}
void Scanner::LiteralBuffer::AddCharSlow(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;
} 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;
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Scanner::BookmarkScope // Scanner::BookmarkScope
......
...@@ -353,36 +353,16 @@ class Scanner { ...@@ -353,36 +353,16 @@ class Scanner {
~LiteralBuffer() { backing_store_.Dispose(); } ~LiteralBuffer() { backing_store_.Dispose(); }
INLINE(void AddChar(char code_unit)) { INLINE(void AddChar(char code_unit)) {
if (position_ >= backing_store_.length()) ExpandBuffer();
DCHECK(is_one_byte_);
DCHECK(IsValidAscii(code_unit)); DCHECK(IsValidAscii(code_unit));
backing_store_[position_] = static_cast<byte>(code_unit); AddOneByteChar(static_cast<byte>(code_unit));
position_ += kOneByteSize;
return;
} }
INLINE(void AddChar(uc32 code_unit)) { INLINE(void AddChar(uc32 code_unit)) {
if (position_ >= backing_store_.length()) ExpandBuffer(); if (is_one_byte_ &&
if (is_one_byte_) { code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) {
if (code_unit <= static_cast<uc32>(unibrow::Latin1::kMaxChar)) { AddOneByteChar(static_cast<byte>(code_unit));
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;
} else { } else {
*reinterpret_cast<uint16_t*>(&backing_store_[position_]) = AddCharSlow(code_unit);
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;
} }
} }
...@@ -434,43 +414,18 @@ class Scanner { ...@@ -434,43 +414,18 @@ class Scanner {
return iscntrl(code_unit) || isprint(code_unit); return iscntrl(code_unit) || isprint(code_unit);
} }
inline int NewCapacity(int min_capacity) { INLINE(void AddOneByteChar(byte one_byte_char)) {
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() {
DCHECK(is_one_byte_); DCHECK(is_one_byte_);
Vector<byte> new_store; if (position_ >= backing_store_.length()) ExpandBuffer();
int new_content_size = position_ * kUC16Size; backing_store_[position_] = one_byte_char;
if (new_content_size >= backing_store_.length()) { position_ += kOneByteSize;
// 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;
} }
void AddCharSlow(uc32 code_unit);
int NewCapacity(int min_capacity);
void ExpandBuffer();
void ConvertToTwoByte();
bool is_one_byte_; bool is_one_byte_;
int position_; int position_;
Vector<byte> backing_store_; Vector<byte> backing_store_;
......
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