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

Unified Diff: runtime/vm/hash_table.h

Issue 612213002: Clear the handle returned by HashTable::Release in ~HashTable. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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/hash_table.h
===================================================================
--- runtime/vm/hash_table.h (revision 40743)
+++ runtime/vm/hash_table.h (working copy)
@@ -44,6 +44,7 @@
// The classes all wrap an Array handle, and metods like HashSet::Insert can
// trigger growth into a new RawArray, updating the handle. Debug mode asserts
// that 'Release' was called once to access the final array before destruction.
+// NOTE: The handle returned by 'Release' is cleared by ~HashTable.
//
// Example use:
// typedef UnorderedHashMap<FooTraits> FooMap;
@@ -90,25 +91,33 @@
: isolate_(isolate),
key_handle_(Object::Handle(isolate_)),
smi_handle_(Smi::Handle(isolate_)),
- data_(&Array::Handle(isolate_, data)) {}
+ data_(&Array::Handle(isolate_, data)),
+ released_data_(NULL) {}
// Like above, except uses current isolate.
explicit HashTable(RawArray* data)
: isolate_(Isolate::Current()),
key_handle_(Object::Handle(isolate_)),
smi_handle_(Smi::Handle(isolate_)),
- data_(&Array::Handle(isolate_, data)) {}
+ data_(&Array::Handle(isolate_, data)),
+ released_data_(NULL) {}
+ // Returns the final table. The handle is cleared when this HashTable is
+ // destroyed.
Array& Release() {
ASSERT(data_ != NULL);
- Array* result = data_;
+ ASSERT(released_data_ == NULL);
// Ensure that no methods are called after 'Release'.
+ released_data_ = data_;
data_ = NULL;
- return *result;
+ return *released_data_;
}
~HashTable() {
- // Ensure that 'Release' was called.
+ // In DEBUG mode, calling 'Release' is mandatory.
ASSERT(data_ == NULL);
+ if (released_data_ != NULL) {
+ *released_data_ = Array::null();
+ }
}
// Returns a backing storage size such that 'num_occupied' distinct keys can
@@ -305,9 +314,9 @@
Isolate* isolate_;
Object& key_handle_;
Smi& smi_handle_;
- // This is a pointer rather than a reference, to enable Release nulling it,
- // preventing post-Release modification.
+ // Exactly one of these is non-NULL, depending on whether Release was called.
Array* data_;
+ Array* released_data_;
friend class HashTables;
};
« 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