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

Unified Diff: runtime/vm/raw_object_snapshot.cc

Issue 8359023: Deserialize string data directly into a newly allocated object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 | « no previous file | 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 e1e339f54b3f34eac8bcaf60c8500e10c9186aab..ef54727ac2e88c4ce8fb22681986faddd0d325ce 100644
--- a/runtime/vm/raw_object_snapshot.cc
+++ b/runtime/vm/raw_object_snapshot.cc
@@ -999,18 +999,13 @@ RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader,
intptr_t len = Smi::Value(smi_len);
RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>());
- // Allocate a one byte character area.
- uint8_t* chars = new uint8_t[len];
- for (int i = 0; i < len; i++) {
- chars[i] = reader->Read<uint8_t>();
- }
-
// Set up the one byte string object.
OneByteString& str_obj = OneByteString::ZoneHandle(
- OneByteString::New(chars,
- len,
- classes_serialized ? Heap::kOld : Heap::kNew));
- delete[] chars;
+ OneByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew));
+ for (intptr_t i = 0; i < len; i++) {
+ *str_obj.CharAddr(i) = reader->Read<uint8_t>();
siva 2011/10/21 20:40:55 *(str_obj.CharAddr(i)) = reader->Read<uint8_t>();
+ }
+
reader->AddBackwardReference(object_id, &str_obj);
RawOneByteString* raw_str = str_obj.raw();
raw_str->ptr()->hash_ = smi_hash;
@@ -1052,18 +1047,13 @@ RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader,
intptr_t len = Smi::Value(smi_len);
RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>());
- // Allocate a two byte character area.
- uint16_t* chars = new uint16_t[len];
+ // Set up the two byte string object.
+ TwoByteString& str_obj = TwoByteString::ZoneHandle(
+ TwoByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew));
for (int i = 0; i < len; i++) {
siva 2011/10/21 20:40:55 int => intptr_t like above?
- chars[i] = reader->Read<uint16_t>();
+ *str_obj.CharAddr(i) = reader->Read<uint16_t>();
siva 2011/10/21 20:40:55 ditto.
}
- // Set up the two byte string object.
- TwoByteString& str_obj = TwoByteString::ZoneHandle(
- TwoByteString::New(chars,
- len,
- classes_serialized ? Heap::kOld : Heap::kNew));
- delete[] chars;
reader->AddBackwardReference(object_id, &str_obj);
RawTwoByteString* raw_str = str_obj.raw();
raw_str->ptr()->hash_ = smi_hash;
@@ -1105,18 +1095,13 @@ RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader,
intptr_t len = Smi::Value(smi_len);
RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>());
- // Allocate a four byte character area.
- uint32_t* chars = new uint32_t[len];
- for (int i = 0; i < len; i++) {
- chars[i] = reader->Read<uint32_t>();
- }
-
// Set up the four byte string object.
FourByteString& str_obj = FourByteString::ZoneHandle(
- FourByteString::New(chars,
- len,
- classes_serialized ? Heap::kOld : Heap::kNew));
- delete[] chars;
+ FourByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew));
+ for (intptr_t i = 0; i < len; i++) {
+ *str_obj.CharAddr(i) = reader->Read<uint32_t>();
siva 2011/10/21 20:40:55 ditto.
+ }
+
reader->AddBackwardReference(object_id, &str_obj);
RawFourByteString* raw_str = str_obj.raw();
raw_str->ptr()->hash_ = smi_hash;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698