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

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

Issue 293993021: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 6 years, 6 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "snapshot-source-sink.h"
6
7 #include "serialize.h" // for SerializerDeserializer::nop() in AtEOF()
8
9 namespace v8 {
10 namespace internal {
11
12
13 SnapshotByteSource::SnapshotByteSource(const byte* array, int length)
14 : data_(array), length_(length), position_(0) {
15 }
16
17
18 SnapshotByteSource::~SnapshotByteSource() { }
19
20
21 int32_t SnapshotByteSource::GetUnalignedInt() {
22 ASSERT(position_ < length_); // Require at least one byte left.
23 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN
24 int32_t answer = *reinterpret_cast<const int32_t*>(data_ + position_);
25 #else
26 int32_t answer = data_[position_];
27 answer |= data_[position_ + 1] << 8;
28 answer |= data_[position_ + 2] << 16;
29 answer |= data_[position_ + 3] << 24;
30 #endif
31 return answer;
32 }
33
34
35 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
36 OS::MemCopy(to, data_ + position_, number_of_bytes);
37 position_ += number_of_bytes;
38 }
39
40
41 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
42 ASSERT(integer < 1 << 22);
43 integer <<= 2;
44 int bytes = 1;
45 if (integer > 0xff) bytes = 2;
46 if (integer > 0xffff) bytes = 3;
47 integer |= bytes;
48 Put(static_cast<int>(integer & 0xff), "IntPart1");
49 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
50 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
51 }
52
53 void SnapshotByteSink::PutRaw(byte* data, int number_of_bytes,
54 const char* description) {
55 for (int i = 0; i < number_of_bytes; ++i) {
56 Put(data[i], description);
57 }
58 }
59
60 void SnapshotByteSink::PutBlob(byte* data, int number_of_bytes,
61 const char* description) {
62 PutInt(number_of_bytes, description);
63 PutRaw(data, number_of_bytes, description);
64 }
65
66
67 bool SnapshotByteSource::AtEOF() {
68 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
69 for (int x = position_; x < length_; x++) {
70 if (data_[x] != SerializerDeserializer::nop()) return false;
71 }
72 return true;
73 }
74
75
76 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
77 int size = GetInt();
78 *number_of_bytes = size;
79
80 if (position_ + size < length_) {
81 *data = &data_[position_];
82 Advance(size);
83 return true;
84 } else {
85 Advance(length_ - position_); // proceed until end.
86 return false;
87 }
88 }
89
90 } // namespace v8::internal
91 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698