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_SNAPSHOT_SOURCE_SINK_H_ | 5 #ifndef V8_SNAPSHOT_SNAPSHOT_SOURCE_SINK_H_ |
6 #define V8_SNAPSHOT_SNAPSHOT_SOURCE_SINK_H_ | 6 #define V8_SNAPSHOT_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 20 matching lines...) Expand all Loading... |
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 void Advance(int by) { position_ += by; } | 39 void Advance(int by) { position_ += by; } |
40 | 40 |
41 void CopyRaw(byte* to, int number_of_bytes) { | 41 void CopyRaw(byte* to, int number_of_bytes); |
42 memcpy(to, data_ + position_, number_of_bytes); | |
43 position_ += number_of_bytes; | |
44 } | |
45 | 42 |
46 inline int GetInt() { | 43 inline int GetInt() { |
47 // This way of decoding variable-length encoded integers does not | 44 // This way of decoding variable-length encoded integers does not |
48 // suffer from branch mispredictions. | 45 // suffer from branch mispredictions. |
49 DCHECK(position_ + 3 < length_); | 46 DCHECK(position_ + 3 < length_); |
50 uint32_t answer = data_[position_]; | 47 uint32_t answer = data_[position_]; |
51 answer |= data_[position_ + 1] << 8; | 48 answer |= data_[position_ + 1] << 8; |
52 answer |= data_[position_ + 2] << 16; | 49 answer |= data_[position_ + 2] << 16; |
53 answer |= data_[position_ + 3] << 24; | 50 answer |= data_[position_ + 3] << 24; |
54 int bytes = (answer & 3) + 1; | 51 int bytes = (answer & 3) + 1; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 const List<byte>* data() const { return &data_; } | 97 const List<byte>* data() const { return &data_; } |
101 | 98 |
102 private: | 99 private: |
103 List<byte> data_; | 100 List<byte> data_; |
104 }; | 101 }; |
105 | 102 |
106 } // namespace internal | 103 } // namespace internal |
107 } // namespace v8 | 104 } // namespace v8 |
108 | 105 |
109 #endif // V8_SNAPSHOT_SNAPSHOT_SOURCE_SINK_H_ | 106 #endif // V8_SNAPSHOT_SNAPSHOT_SOURCE_SINK_H_ |
OLD | NEW |