| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_ | 5 #ifndef V8_SNAPSHOT_SOURCE_SINK_H_ |
| 6 #define V8_SNAPSHOT_SOURCE_SINK_H_ | 6 #define V8_SNAPSHOT_SOURCE_SINK_H_ |
| 7 | 7 |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 ~SnapshotByteSource() {} | 30 ~SnapshotByteSource() {} |
| 31 | 31 |
| 32 bool HasMore() { return position_ < length_; } | 32 bool HasMore() { return position_ < length_; } |
| 33 | 33 |
| 34 byte Get() { | 34 byte Get() { |
| 35 DCHECK(position_ < length_); | 35 DCHECK(position_ < length_); |
| 36 return data_[position_++]; | 36 return data_[position_++]; |
| 37 } | 37 } |
| 38 | 38 |
| 39 int32_t GetUnalignedInt(); | |
| 40 | |
| 41 void Advance(int by) { position_ += by; } | 39 void Advance(int by) { position_ += by; } |
| 42 | 40 |
| 43 void CopyRaw(byte* to, int number_of_bytes); | 41 void CopyRaw(byte* to, int number_of_bytes); |
| 44 | 42 |
| 45 inline int GetInt() { | 43 inline int GetInt() { |
| 46 // This way of variable-length encoding integers does not suffer from branch | 44 // This way of decoding variable-length encoded integers does not |
| 47 // mispredictions. | 45 // suffer from branch mispredictions. |
| 48 uint32_t answer = GetUnalignedInt(); | 46 DCHECK(position_ + 3 < length_); |
| 47 uint32_t answer = data_[position_]; |
| 48 answer |= data_[position_ + 1] << 8; |
| 49 answer |= data_[position_ + 2] << 16; |
| 50 answer |= data_[position_ + 3] << 24; |
| 49 int bytes = (answer & 3) + 1; | 51 int bytes = (answer & 3) + 1; |
| 50 Advance(bytes); | 52 Advance(bytes); |
| 51 uint32_t mask = 0xffffffffu; | 53 uint32_t mask = 0xffffffffu; |
| 52 mask >>= 32 - (bytes << 3); | 54 mask >>= 32 - (bytes << 3); |
| 53 answer &= mask; | 55 answer &= mask; |
| 54 answer >>= 2; | 56 answer >>= 2; |
| 55 return answer; | 57 return answer; |
| 56 } | 58 } |
| 57 | 59 |
| 58 bool GetBlob(const byte** data, int* number_of_bytes); | 60 bool GetBlob(const byte** data, int* number_of_bytes); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const List<byte>& data() const { return data_; } | 98 const List<byte>& data() const { return data_; } |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 List<byte> data_; | 101 List<byte> data_; |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 } // namespace v8::internal | 104 } // namespace v8::internal |
| 103 } // namespace v8 | 105 } // namespace v8 |
| 104 | 106 |
| 105 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ | 107 #endif // V8_SNAPSHOT_SOURCE_SINK_H_ |
| OLD | NEW |