]> git.lizzy.rs Git - rust.git/commitdiff
Fix some bad code in the dict interner
authorMarijn Haverbeke <marijnh@gmail.com>
Sat, 7 Jan 2012 19:04:16 +0000 (20:04 +0100)
committerMarijn Haverbeke <marijnh@gmail.com>
Sun, 8 Jan 2012 20:57:54 +0000 (21:57 +0100)
Issue #1436

src/rt/rust_crate_cache.cpp
src/rt/rust_scheduler.h

index 6fcb0fc699e43ce2cdd2e5eb6fe859f5ed617379..17e5f34e5343cd04cfe0619191bd41f0139e610d 100644 (file)
@@ -48,21 +48,16 @@ rust_crate_cache::get_type_desc(size_t size,
 void**
 rust_crate_cache::get_dict(size_t n_fields, void** dict) {
     rust_hashable_dict *found = NULL;
-    uintptr_t key = 0;
-    for (size_t i = 0; i < n_fields; ++i) key ^= (uintptr_t)dict[i];
-    size_t keysz = sizeof(uintptr_t);
-    HASH_FIND(hh, this->dicts, &key, keysz, found);
-    if (found) { printf("found!\n"); return &(found->fields[0]); }
-    printf("not found\n");
-    size_t dictsz = n_fields * sizeof(void*);
+    size_t dictsz = sizeof(void*) * n_fields;
+    HASH_FIND(hh, this->dicts, dict, dictsz, found);
+    if (found) return &(found->fields[0]);
     found = (rust_hashable_dict*)
-        sched->kernel->malloc(keysz + sizeof(UT_hash_handle) + dictsz,
+        sched->kernel->malloc(sizeof(UT_hash_handle) + dictsz,
                               "crate cache dict");
     if (!found) return NULL;
-    found->key = key;
     void** retptr = &(found->fields[0]);
     memcpy(retptr, dict, dictsz);
-    HASH_ADD(hh, this->dicts, key, keysz, found);
+    HASH_ADD_KEYPTR(hh, this->dicts, retptr, dictsz, found);
     return retptr;
 }
 
index 75dce82d31813b885b7cbffff230c874956cb6a4..4980264601162b7933387f18156ab950cfc51f41 100644 (file)
@@ -12,7 +12,6 @@
 struct rust_scheduler;
 
 struct rust_hashable_dict {
-    uintptr_t key;
     UT_hash_handle hh;
     void* fields[0];
 };