Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: src/snapshot-source-sink.cc

Issue 780833002: Revert of Encode reservation meta data in the snapshot blob. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@snapshotformat
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot-source-sink.h ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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()
11 11
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16
17 SnapshotByteSource::SnapshotByteSource(const byte* array, int length)
18 : data_(array), length_(length), position_(0) {
19 }
20
21
22 SnapshotByteSource::~SnapshotByteSource() { }
23
24
16 int32_t SnapshotByteSource::GetUnalignedInt() { 25 int32_t SnapshotByteSource::GetUnalignedInt() {
17 DCHECK(position_ < length_); // Require at least one byte left. 26 DCHECK(position_ < length_); // Require at least one byte left.
18 int32_t answer = data_[position_]; 27 int32_t answer = data_[position_];
19 answer |= data_[position_ + 1] << 8; 28 answer |= data_[position_ + 1] << 8;
20 answer |= data_[position_ + 2] << 16; 29 answer |= data_[position_ + 2] << 16;
21 answer |= data_[position_ + 3] << 24; 30 answer |= data_[position_ + 3] << 24;
22 return answer; 31 return answer;
23 } 32 }
24 33
25 34
(...skipping 10 matching lines...) Expand all
36 if (integer > 0xff) bytes = 2; 45 if (integer > 0xff) bytes = 2;
37 if (integer > 0xffff) bytes = 3; 46 if (integer > 0xffff) bytes = 3;
38 if (integer > 0xffffff) bytes = 4; 47 if (integer > 0xffffff) bytes = 4;
39 integer |= (bytes - 1); 48 integer |= (bytes - 1);
40 Put(static_cast<int>(integer & 0xff), "IntPart1"); 49 Put(static_cast<int>(integer & 0xff), "IntPart1");
41 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2"); 50 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
42 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3"); 51 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
43 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4"); 52 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
44 } 53 }
45 54
55 void SnapshotByteSink::PutRaw(byte* data, int number_of_bytes,
56 const char* description) {
57 data_.AddAll(Vector<byte>(data, number_of_bytes));
58 }
46 59
47 void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes, 60 void SnapshotByteSink::PutBlob(byte* data, int number_of_bytes,
48 const char* description) { 61 const char* description) {
49 data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes)); 62 PutInt(number_of_bytes, description);
63 PutRaw(data, number_of_bytes, description);
50 } 64 }
51 65
52 66
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() { 67 bool SnapshotByteSource::AtEOF() {
61 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; 68 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
62 for (int x = position_; x < length_; x++) { 69 for (int x = position_; x < length_; x++) {
63 if (data_[x] != SerializerDeserializer::nop()) return false; 70 if (data_[x] != SerializerDeserializer::nop()) return false;
64 } 71 }
65 return true; 72 return true;
66 } 73 }
67 74
68 75
69 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) { 76 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
70 int size = GetInt(); 77 int size = GetInt();
71 *number_of_bytes = size; 78 *number_of_bytes = size;
72 79
73 if (position_ + size < length_) { 80 if (position_ + size < length_) {
74 *data = &data_[position_]; 81 *data = &data_[position_];
75 Advance(size); 82 Advance(size);
76 return true; 83 return true;
77 } else { 84 } else {
78 Advance(length_ - position_); // proceed until end. 85 Advance(length_ - position_); // proceed until end.
79 return false; 86 return false;
80 } 87 }
81 } 88 }
82 89
83 } // namespace v8::internal 90 } // namespace v8::internal
84 } // namespace v8 91 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot-source-sink.h ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698