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

Unified Diff: runtime/vm/raw_object_snapshot.cc

Issue 9195031: Add ByteArray interface and provide internal and external implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address remaining review comments Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/raw_object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/raw_object_snapshot.cc
diff --git a/runtime/vm/raw_object_snapshot.cc b/runtime/vm/raw_object_snapshot.cc
index 9bc6c79747dbf2e33c923021500e95bfbd00c99b..80d53b23fe431687d8a5e4c38ed22a928889c063 100644
--- a/runtime/vm/raw_object_snapshot.cc
+++ b/runtime/vm/raw_object_snapshot.cc
@@ -1637,19 +1637,106 @@ void RawImmutableArray::WriteTo(SnapshotWriter* writer,
}
-RawByteBuffer* ByteBuffer::ReadFrom(SnapshotReader* reader,
- intptr_t object_id,
- intptr_t tags,
- Snapshot::Kind kind) {
- UNIMPLEMENTED();
- return ByteBuffer::null();
+RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader,
+ intptr_t object_id,
+ intptr_t tags,
+ Snapshot::Kind kind) {
+ UNREACHABLE(); // ByteArray is an abstract class.
+ return ByteArray::null();
}
-void RawByteBuffer::WriteTo(SnapshotWriter* writer,
- intptr_t object_id,
- Snapshot::Kind kind) {
- UNIMPLEMENTED();
+RawInternalByteArray* InternalByteArray::ReadFrom(SnapshotReader* reader,
+ intptr_t object_id,
+ intptr_t tags,
+ Snapshot::Kind kind) {
+ ASSERT(reader != NULL);
+
+ // Read the length so that we can determine instance size to allocate.
+ intptr_t len = GetSmiValue(reader->ReadIntptrValue());
+ Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew;
+ InternalByteArray& result =
+ InternalByteArray::ZoneHandle(reader->isolate(),
+ InternalByteArray::New(len, space));
+ reader->AddBackwardReference(object_id, &result);
+
+ // Set the object tags.
+ result.set_tags(tags);
+
+ // Setup the array elements.
+ for (intptr_t i = 0; i < len; i++) {
+ result.SetAt<uint8_t>(i, reader->Read<uint8_t>());
+ }
+ return result.raw();
+}
+
+
+RawExternalByteArray* ExternalByteArray::ReadFrom(SnapshotReader* reader,
+ intptr_t object_id,
+ intptr_t tags,
+ Snapshot::Kind kind) {
+ UNREACHABLE();
+ return ExternalByteArray::null();
+}
+
+
+static void ByteArrayWriteTo(SnapshotWriter* writer,
+ intptr_t object_id,
+ Snapshot::Kind kind,
+ intptr_t byte_array_kind,
+ intptr_t tags,
+ RawSmi* length,
+ uint8_t* data) {
+ ASSERT(writer != NULL);
+ intptr_t len = Smi::Value(length);
+
+ // Write out the serialization header value for this object.
+ writer->WriteSerializationMarker(kInlined, object_id);
+
+ // Write out the class and tags information.
+ writer->WriteObjectHeader(byte_array_kind, tags);
+
+ // Write out the length field.
+ writer->Write<RawObject*>(length);
+
+ // Write out the array elements.
+ for (intptr_t i = 0; i < len; i++) {
+ writer->Write(data[i]);
+ }
+}
+
+
+void RawByteArray::WriteTo(SnapshotWriter* writer,
+ intptr_t object_id,
+ Snapshot::Kind kind) {
+ UNREACHABLE(); // ByteArray is an abstract class
+}
+
+
+void RawInternalByteArray::WriteTo(SnapshotWriter* writer,
+ intptr_t object_id,
+ Snapshot::Kind kind) {
+ ByteArrayWriteTo(writer,
+ object_id,
+ kind,
+ ObjectStore::kInternalByteArrayClass,
+ ptr()->tags_,
+ ptr()->length_,
+ ptr()->data());
+}
+
+
+void RawExternalByteArray::WriteTo(SnapshotWriter* writer,
+ intptr_t object_id,
+ Snapshot::Kind kind) {
+ // Serialize as an internal byte array.
+ ByteArrayWriteTo(writer,
+ object_id,
+ kind,
+ ObjectStore::kInternalByteArrayClass,
+ ptr()->tags_,
+ ptr()->length_,
+ ptr()->data_);
}
« no previous file with comments | « runtime/vm/raw_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698