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

Unified Diff: runtime/vm/hash_map.h

Issue 848703002: Improve constant pool implementation in the assembler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 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
« runtime/vm/assembler_x64.h ('K') | « runtime/vm/flow_graph.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/hash_map.h
===================================================================
--- runtime/vm/hash_map.h (revision 42727)
+++ runtime/vm/hash_map.h (working copy)
@@ -31,8 +31,8 @@
void Clear() {
if (!IsEmpty()) {
count_ = 0;
- memset(array_, 0, sizeof(HashMapListElement) * array_size_);
- memset(lists_, 0, sizeof(HashMapListElement) * lists_size_);
+ InitArray(array_, array_size_);
+ InitArray(lists_, lists_size_);
lists_[0].next = kNil;
for (intptr_t i = 1; i < lists_size_; ++i) {
lists_[i].next = i - 1;
@@ -44,11 +44,18 @@
protected:
// A linked list of T values. Stored in arrays.
struct HashMapListElement {
+ HashMapListElement() : kv(KeyValueTrait::NoValue()), next(kNil) { }
typename KeyValueTrait::Pair kv;
intptr_t next; // Index in the array of the next list element.
};
static const intptr_t kNil = -1; // The end of a linked list
+ static void InitArray(HashMapListElement* array, intptr_t size) {
+ for (intptr_t i = 0; i < size; ++i) {
+ array[i] = HashMapListElement();
+ }
+ }
+
// Must be a power of 2.
static const intptr_t kInitialSize = 16;
@@ -70,8 +77,7 @@
typename KeyValueTrait::Value
DirectChainedHashMap<KeyValueTrait>::
Lookup(typename KeyValueTrait::Key key) const {
- const typename KeyValueTrait::Value kNoValue =
- static_cast<typename KeyValueTrait::Value>(0);
+ const typename KeyValueTrait::Value kNoValue = KeyValueTrait::NoValue();
uword hash = static_cast<uword>(KeyValueTrait::Hashcode(key));
uword pos = Bound(hash);
@@ -111,8 +117,7 @@
template <typename KeyValueTrait>
void DirectChainedHashMap<KeyValueTrait>::Resize(intptr_t new_size) {
- const typename KeyValueTrait::Value kNoValue =
- static_cast<typename KeyValueTrait::Value>(0);
+ const typename KeyValueTrait::Value kNoValue = KeyValueTrait::NoValue();
ASSERT(new_size > count_);
// Hashing the values into the new array has no more collisions than in the
@@ -125,7 +130,7 @@
HashMapListElement* new_array =
Isolate::Current()->current_zone()->Alloc<HashMapListElement>(new_size);
- memset(new_array, 0, sizeof(HashMapListElement) * new_size);
+ InitArray(new_array, new_size);
HashMapListElement* old_array = array_;
intptr_t old_size = array_size_;
@@ -164,7 +169,7 @@
HashMapListElement* new_lists =
Isolate::Current()->current_zone()->
Alloc<HashMapListElement>(new_size);
- memset(new_lists, 0, sizeof(HashMapListElement) * new_size);
+ InitArray(new_lists, new_size);
HashMapListElement* old_lists = lists_;
intptr_t old_size = lists_size_;
@@ -185,8 +190,7 @@
template <typename KeyValueTrait>
void DirectChainedHashMap<KeyValueTrait>::
Insert(typename KeyValueTrait::Pair kv) {
- const typename KeyValueTrait::Value kNoValue =
- static_cast<typename KeyValueTrait::Value>(0);
+ const typename KeyValueTrait::Value kNoValue = KeyValueTrait::NoValue();
ASSERT(KeyValueTrait::ValueOf(kv) != kNoValue);
// Resizing when half of the hashtable is filled up.
@@ -229,6 +233,8 @@
return kv;
}
+ static Value NoValue() { return NULL; }
+
static inline intptr_t Hashcode(Key key) {
return key->Hashcode();
}
« runtime/vm/assembler_x64.h ('K') | « runtime/vm/flow_graph.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698