Serializer: micro-optimizations for the deserializer.

R=vogelheim@chromium.org

Review URL: https://codereview.chromium.org/1008923003

Cr-Commit-Position: refs/heads/master@{#27230}
This commit is contained in:
yangguo 2015-03-17 02:23:35 -07:00 committed by Commit bot
parent 4a99e6f493
commit 773f297738
3 changed files with 8 additions and 18 deletions

View File

@ -508,9 +508,7 @@ void Deserializer::DecodeReservation(
DCHECK_EQ(0, reservations_[NEW_SPACE].length()); DCHECK_EQ(0, reservations_[NEW_SPACE].length());
STATIC_ASSERT(NEW_SPACE == 0); STATIC_ASSERT(NEW_SPACE == 0);
int current_space = NEW_SPACE; int current_space = NEW_SPACE;
for (int i = 0; i < res.length(); i++) { for (auto& r : res) {
SerializedData::Reservation r(0);
memcpy(&r, res.start() + i, sizeof(r));
reservations_[current_space].Add({r.chunk_size(), NULL, NULL}); reservations_[current_space].Add({r.chunk_size(), NULL, NULL});
if (r.is_last()) current_space++; if (r.is_last()) current_space++;
} }

View File

@ -13,16 +13,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
int32_t SnapshotByteSource::GetUnalignedInt() {
DCHECK(position_ < length_); // Require at least one byte left.
int32_t answer = data_[position_];
answer |= data_[position_ + 1] << 8;
answer |= data_[position_ + 2] << 16;
answer |= data_[position_ + 3] << 24;
return answer;
}
void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) { void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
MemCopy(to, data_ + position_, number_of_bytes); MemCopy(to, data_ + position_, number_of_bytes);
position_ += number_of_bytes; position_ += number_of_bytes;

View File

@ -36,16 +36,18 @@ class SnapshotByteSource FINAL {
return data_[position_++]; return data_[position_++];
} }
int32_t GetUnalignedInt();
void Advance(int by) { position_ += by; } void Advance(int by) { position_ += by; }
void CopyRaw(byte* to, int number_of_bytes); void CopyRaw(byte* to, int number_of_bytes);
inline int GetInt() { inline int GetInt() {
// This way of variable-length encoding integers does not suffer from branch // This way of decoding variable-length encoded integers does not
// mispredictions. // suffer from branch mispredictions.
uint32_t answer = GetUnalignedInt(); DCHECK(position_ + 3 < length_);
uint32_t answer = data_[position_];
answer |= data_[position_ + 1] << 8;
answer |= data_[position_ + 2] << 16;
answer |= data_[position_ + 3] << 24;
int bytes = (answer & 3) + 1; int bytes = (answer & 3) + 1;
Advance(bytes); Advance(bytes);
uint32_t mask = 0xffffffffu; uint32_t mask = 0xffffffffu;