Index: runtime/platform/hashmap.cc |
diff --git a/runtime/platform/hashmap.cc b/runtime/platform/hashmap.cc |
index 693367fc74108fbe66920a286f00784e41a32c5d..34f7ea1284f9f48b38890c95496935551556dcd3 100644 |
--- a/runtime/platform/hashmap.cc |
+++ b/runtime/platform/hashmap.cc |
@@ -15,7 +15,7 @@ HashMap::HashMap(MatchFun match, uint32_t initial_capacity) { |
HashMap::~HashMap() { |
- free(map_); |
+ delete[] map_; |
} |
@@ -106,14 +106,19 @@ void HashMap::Remove(void* key, uint32_t hash) { |
// Clear the candidate which will not break searching the hash table. |
candidate->key = NULL; |
+ candidate->value = NULL; |
occupancy_--; |
} |
-void HashMap::Clear() { |
+void HashMap::Clear(ClearFun clear) { |
// Mark all entries as empty. |
const Entry* end = map_end(); |
for (Entry* p = map_; p < end; p++) { |
+ if ((clear != NULL) && (p->key != NULL)) { |
+ clear(p->value); |
+ } |
+ p->value = NULL; |
p->key = NULL; |
} |
occupancy_ = 0; |
@@ -159,14 +164,14 @@ HashMap::Entry* HashMap::Probe(void* key, uint32_t hash) { |
void HashMap::Initialize(uint32_t capacity) { |
ASSERT(dart::Utils::IsPowerOfTwo(capacity)); |
- map_ = reinterpret_cast<Entry*>(malloc(capacity * sizeof(Entry))); |
+ map_ = new Entry[capacity]; |
if (map_ == NULL) { |
// TODO(sgjesse): Handle out of memory. |
FATAL("Cannot allocate memory for hashmap"); |
return; |
} |
capacity_ = capacity; |
- Clear(); |
+ occupancy_ = 0; |
} |
@@ -186,7 +191,7 @@ void HashMap::Resize() { |
} |
// Delete old map. |
- free(map); |
+ delete[] map; |
} |
} // namespace dart |