ck_ht: Do not re-hash on growth for non-PP case.

We already store the hash value in the hash table entry
if pointer packing is not enabled.
ck_pring
Samy Al Bahra 13 years ago
parent ccb1fd6d86
commit 59158c824b

@ -188,12 +188,19 @@ ck_ht_entry_set(struct ck_ht_entry *entry,
CK_CC_INLINE static void CK_CC_INLINE static void
ck_ht_entry_set_direct(struct ck_ht_entry *entry, ck_ht_entry_set_direct(struct ck_ht_entry *entry,
ck_ht_hash_t h,
uintptr_t key, uintptr_t key,
uintptr_t value) uintptr_t value)
{ {
entry->key = key; entry->key = key;
entry->value = value; entry->value = value;
#ifndef CK_HT_PP
entry->hash = h.value;
#else
(void)h;
#endif
return; return;
} }

@ -162,7 +162,7 @@ table_replace(uintptr_t value)
ck_ht_hash_t h; ck_ht_hash_t h;
ck_ht_hash_direct(&h, &ht, value); ck_ht_hash_direct(&h, &ht, value);
ck_ht_entry_set_direct(&entry, value, 6605241); ck_ht_entry_set_direct(&entry, h, value, 6605241);
return ck_ht_set_spmc(&ht, h, &entry); return ck_ht_set_spmc(&ht, h, &entry);
} }
@ -187,7 +187,7 @@ table_insert(uintptr_t value)
ck_ht_hash_t h; ck_ht_hash_t h;
ck_ht_hash_direct(&h, &ht, value); ck_ht_hash_direct(&h, &ht, value);
ck_ht_entry_set_direct(&entry, value, value); ck_ht_entry_set_direct(&entry, h, value, value);
return ck_ht_put_spmc(&ht, h, &entry); return ck_ht_put_spmc(&ht, h, &entry);
} }

@ -254,7 +254,7 @@ main(void)
l = 0; l = 0;
for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) { for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
ck_ht_hash_direct(&h, &ht, direct[i]); ck_ht_hash_direct(&h, &ht, direct[i]);
ck_ht_entry_set_direct(&entry, direct[i], (uintptr_t)test[i]); ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)test[i]);
l += ck_ht_put_spmc(&ht, h, &entry) == false; l += ck_ht_put_spmc(&ht, h, &entry) == false;
} }
@ -265,7 +265,7 @@ main(void)
for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) { for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
ck_ht_hash_direct(&h, &ht, direct[i]); ck_ht_hash_direct(&h, &ht, direct[i]);
ck_ht_entry_set_direct(&entry, direct[i], (uintptr_t)"REPLACED"); ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)"REPLACED");
l += ck_ht_set_spmc(&ht, h, &entry) == false; l += ck_ht_set_spmc(&ht, h, &entry) == false;
} }

@ -404,9 +404,17 @@ restart:
key = ck_ht_entry_key(previous); key = ck_ht_entry_key(previous);
key_length = ck_ht_entry_key_length(previous); key_length = ck_ht_entry_key_length(previous);
#ifndef CK_HT_PP
h.value = previous->hash;
#else
table->h(&h, key, key_length, table->seed); table->h(&h, key, key_length, table->seed);
#endif
} else { } else {
#ifndef CK_HT_PP
h.value = previous->hash;
#else
table->h(&h, &previous->key, sizeof(previous->key), table->seed); table->h(&h, &previous->key, sizeof(previous->key), table->seed);
#endif
} }
offset = h.value & update->mask; offset = h.value & update->mask;

Loading…
Cancel
Save