Skip to content

Commit 9a7061d

Browse files
committed
Fix some bad code in the dict interner
Issue #1436
1 parent e3afc78 commit 9a7061d

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/rt/rust_crate_cache.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,16 @@ rust_crate_cache::get_type_desc(size_t size,
4848
void**
4949
rust_crate_cache::get_dict(size_t n_fields, void** dict) {
5050
rust_hashable_dict *found = NULL;
51-
uintptr_t key = 0;
52-
for (size_t i = 0; i < n_fields; ++i) key ^= (uintptr_t)dict[i];
53-
size_t keysz = sizeof(uintptr_t);
54-
HASH_FIND(hh, this->dicts, &key, keysz, found);
55-
if (found) { printf("found!\n"); return &(found->fields[0]); }
56-
printf("not found\n");
57-
size_t dictsz = n_fields * sizeof(void*);
51+
size_t dictsz = sizeof(void*) * n_fields;
52+
HASH_FIND(hh, this->dicts, dict, dictsz, found);
53+
if (found) return &(found->fields[0]);
5854
found = (rust_hashable_dict*)
59-
sched->kernel->malloc(keysz + sizeof(UT_hash_handle) + dictsz,
55+
sched->kernel->malloc(sizeof(UT_hash_handle) + dictsz,
6056
"crate cache dict");
6157
if (!found) return NULL;
62-
found->key = key;
6358
void** retptr = &(found->fields[0]);
6459
memcpy(retptr, dict, dictsz);
65-
HASH_ADD(hh, this->dicts, key, keysz, found);
60+
HASH_ADD_KEYPTR(hh, this->dicts, retptr, dictsz, found);
6661
return retptr;
6762
}
6863

src/rt/rust_scheduler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
struct rust_scheduler;
1313

1414
struct rust_hashable_dict {
15-
uintptr_t key;
1615
UT_hash_handle hh;
1716
void* fields[0];
1817
};

0 commit comments

Comments
 (0)