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

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: Created 6 years, 7 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 int32_t SnapshotByteSource::GetUnalignedInt() {
19 ASSERT(position_ < length_); // Require at least one byte left.
20 #if defined(V8_HOST_CAN_READ_UNALIGNED) && __BYTE_ORDER == __LITTLE_ENDIAN
21 int32_t answer = *reinterpret_cast<const int32_t*>(data_ + position_);
22 #else
23 int32_t answer = data_[position_];
24 answer |= data_[position_ + 1] << 8;
25 answer |= data_[position_ + 2] << 16;
26 answer |= data_[position_ + 3] << 24;
27 #endif
28 return answer;
29 }
30
31
32 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
33 OS::MemCopy(to, data_ + position_, number_of_bytes);
34 position_ += number_of_bytes;
35 }
36
37
38 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
39 ASSERT(integer < 1 << 22);
40 integer <<= 2;
41 int bytes = 1;
42 if (integer > 0xff) bytes = 2;
43 if (integer > 0xffff) bytes = 3;
44 integer |= bytes;
45 Put(static_cast<int>(integer & 0xff), "IntPart1");
46 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
47 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
48 }
49
50 void SnapshotByteSink::PutRaw(byte* data, int number_of_bytes,
51 const char* description) {
52 for (int i = 0; i < number_of_bytes; ++i) {
53 Put(data[i], description);
54 }
55 }
56
57 void SnapshotByteSink::PutBlob(byte* data, int number_of_bytes,
58 const char* description) {
59 PutInt(number_of_bytes, description);
60 PutRaw(data, number_of_bytes, description);
61 }
62
63
64 bool SnapshotByteSource::AtEOF() {
65 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
66 for (int x = position_; x < length_; x++) {
67 if (data_[x] != SerializerDeserializer::nop()) return false;
68 }
69 return true;
70 }
71
72
73 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
74 int size = GetInt();
75 *number_of_bytes = size;
76
77 if (position_ + size < length_) {
78 *data = &data_[position_];
79 Advance(size);
80 return true;
81 } else {
82 Advance(length_ - position_); // proceed until end.
83 return false;
84 }
85 }
86
87 } // namespace v8::internal
88 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698