about summary refs log tree commit diff
path: root/src/rt/rust_crate_cache.cpp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-07 20:04:16 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-08 21:57:54 +0100
commit9a7061dfab73caeea215a99a5d8cca26360fe99e (patch)
treeb41557c5577c0407092d981fb987a74c65825497 /src/rt/rust_crate_cache.cpp
parente3afc78fde5c614995dd4f2c76da160a321c8f5d (diff)
downloadrust-9a7061dfab73caeea215a99a5d8cca26360fe99e.tar.gz
rust-9a7061dfab73caeea215a99a5d8cca26360fe99e.zip
Fix some bad code in the dict interner
Issue #1436
Diffstat (limited to 'src/rt/rust_crate_cache.cpp')
-rw-r--r--src/rt/rust_crate_cache.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/rt/rust_crate_cache.cpp b/src/rt/rust_crate_cache.cpp
index 6fcb0fc699e..17e5f34e534 100644
--- a/src/rt/rust_crate_cache.cpp
+++ b/src/rt/rust_crate_cache.cpp
@@ -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;
 }