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

Unified Diff: runtime/vm/dart_api_message.cc

Issue 11415048: Deserialize same symbol as same Dart_CObject (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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/dart_api_message.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_message.cc
diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc
index 64eea311b36bbefba79d1888f3a34d9b83c4fc4d..b661136f5dbbda611ce071d400ef005ac19db8ce 100644
--- a/runtime/vm/dart_api_message.cc
+++ b/runtime/vm/dart_api_message.cc
@@ -17,7 +17,8 @@ ApiMessageReader::ApiMessageReader(const uint8_t* buffer,
ReAlloc alloc)
: BaseReader(buffer, length),
alloc_(alloc),
- backward_references_(kNumInitialReferences) {
+ backward_references_(kNumInitialReferences),
+ vm_symbol_references_(NULL) {
Init();
}
@@ -215,13 +216,31 @@ Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) {
Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) {
if (Symbols::IsVMSymbolId(object_id)) {
+ intptr_t symbol_id = object_id - kMaxPredefinedObjectIds;
+ Dart_CObject* object;
+ if (vm_symbol_references_ != NULL &&
+ (object = vm_symbol_references_[symbol_id]) != NULL) {
+ return object;
+ }
+
+ if (vm_symbol_references_ == NULL) {
+ intptr_t size = sizeof(*vm_symbol_references_) * Symbols::kMaxId;
+ vm_symbol_references_ =
+ reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size));
+#ifdef DEBUG
Florian Schneider 2012/11/19 14:30:08 I think you need to zero-initialize this array in
Søren Gjesse 2012/11/19 14:54:47 Absolutely, thanks for spotting.
+ memset(vm_symbol_references_, 0, size);
+#endif
+ }
+
RawOneByteString* str =
reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id));
intptr_t len = Smi::Value(str->ptr()->length_);
- Dart_CObject* object = AllocateDartCObjectString(len);
+ object = AllocateDartCObjectString(len);
char* p = object->value.as_string;
memmove(p, str->ptr()->data_, len);
p[len] = '\0';
+ ASSERT(vm_symbol_references_[symbol_id] == NULL);
+ vm_symbol_references_[symbol_id] = object;
return object;
}
// No other VM isolate objects are supported.
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698