Commit 773f2977 authored by yangguo's avatar yangguo Committed by Commit bot

Serializer: micro-optimizations for the deserializer.

R=vogelheim@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27230}
parent 4a99e6f4
...@@ -508,9 +508,7 @@ void Deserializer::DecodeReservation( ...@@ -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++;
} }
......
...@@ -13,16 +13,6 @@ ...@@ -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;
......
...@@ -36,16 +36,18 @@ class SnapshotByteSource FINAL { ...@@ -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;
......
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