| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
| 6 #include "src/snapshot-source-sink.h" | 6 #include "src/snapshot-source-sink.h" |
| 7 | 7 |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/handles-inl.h" | 9 #include "src/handles-inl.h" |
| 10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF() | 10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4"); | 43 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes, | 47 void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes, |
| 48 const char* description) { | 48 const char* description) { |
| 49 data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes)); | 49 data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 void SnapshotByteSink::PutBlob(Vector<const byte> blob, | |
| 54 const char* description) { | |
| 55 PutInt(blob.length(), description); | |
| 56 PutRaw(blob.start(), blob.length(), description); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 bool SnapshotByteSource::AtEOF() { | 53 bool SnapshotByteSource::AtEOF() { |
| 61 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; | 54 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; |
| 62 for (int x = position_; x < length_; x++) { | 55 for (int x = position_; x < length_; x++) { |
| 63 if (data_[x] != SerializerDeserializer::nop()) return false; | 56 if (data_[x] != SerializerDeserializer::nop()) return false; |
| 64 } | 57 } |
| 65 return true; | 58 return true; |
| 66 } | 59 } |
| 67 | 60 |
| 68 | 61 |
| 69 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) { | 62 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) { |
| 70 int size = GetInt(); | 63 int size = GetInt(); |
| 71 *number_of_bytes = size; | 64 *number_of_bytes = size; |
| 72 | 65 |
| 73 if (position_ + size <= length_) { | 66 if (position_ + size <= length_) { |
| 74 *data = &data_[position_]; | 67 *data = &data_[position_]; |
| 75 Advance(size); | 68 Advance(size); |
| 76 return true; | 69 return true; |
| 77 } else { | 70 } else { |
| 78 Advance(length_ - position_); // proceed until end. | 71 Advance(length_ - position_); // proceed until end. |
| 79 return false; | 72 return false; |
| 80 } | 73 } |
| 81 } | 74 } |
| 82 | 75 |
| 83 } // namespace v8::internal | 76 } // namespace v8::internal |
| 84 } // namespace v8 | 77 } // namespace v8 |
| OLD | NEW |