Serializer: micro-optimizations for the deserializer.
authoryangguo <yangguo@chromium.org>
Tue, 17 Mar 2015 09:23:35 +0000 (02:23 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 17 Mar 2015 09:23:42 +0000 (09:23 +0000)
R=vogelheim@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27230}

src/serialize.cc
src/snapshot-source-sink.cc
src/snapshot-source-sink.h

index a7cfda8..00405dd 100644 (file)
@@ -508,9 +508,7 @@ void Deserializer::DecodeReservation(
   DCHECK_EQ(0, reservations_[NEW_SPACE].length());
   STATIC_ASSERT(NEW_SPACE == 0);
   int current_space = NEW_SPACE;
-  for (int i = 0; i < res.length(); i++) {
-    SerializedData::Reservation r(0);
-    memcpy(&r, res.start() + i, sizeof(r));
+  for (auto& r : res) {
     reservations_[current_space].Add({r.chunk_size(), NULL, NULL});
     if (r.is_last()) current_space++;
   }
index fd94724..0054aec 100644 (file)
 namespace v8 {
 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) {
   MemCopy(to, data_ + position_, number_of_bytes);
   position_ += number_of_bytes;
index 66feaec..6612029 100644 (file)
@@ -36,16 +36,18 @@ class SnapshotByteSource FINAL {
     return data_[position_++];
   }
 
-  int32_t GetUnalignedInt();
-
   void Advance(int by) { position_ += by; }
 
   void CopyRaw(byte* to, int number_of_bytes);
 
   inline int GetInt() {
-    // This way of variable-length encoding integers does not suffer from branch
-    // mispredictions.
-    uint32_t answer = GetUnalignedInt();
+    // This way of decoding variable-length encoded integers does not
+    // suffer from branch mispredictions.
+    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;
     Advance(bytes);
     uint32_t mask = 0xffffffffu;