}
}
+/* Compare function for 'gen' hash table. No need to compare the key
+ in this function, as the hash table already does it for us,
+ and that in any case, if the data is equal, the keys must also be
+ equal. */
static Word cmp_pool_elt (const void* node1, const void* node2 )
{
const ht_node* hnode1 = node1;
const ht_node* hnode2 = node2;
- if (hnode1->key < hnode2->key)
- return -1;
- else if (hnode1->key > hnode2->key)
- return 1;
- else if (hnode1->eltSzB == hnode2->eltSzB)
+ /* As this function is called by hashtable, that has already checked
+ for key equality, it is likely that it is the 'good' element.
+ So, we handle the equal case first. */
+ if (hnode1->eltSzB == hnode2->eltSzB)
return VG_(memcmp) (hnode1->elt, hnode2->elt, hnode1->eltSzB);
else if (hnode1->eltSzB < hnode2->eltSzB)
return -1;
VgHashNode* curr = table->chains[ CHAIN_NO(hnode->key, table) ]; // GEN!!!
while (curr) {
- if (cmp (hnode, curr) == 0) { // GEN!!!
+ if (hnode->key == curr->key && cmp (hnode, curr) == 0) { // GEN!!!
return curr;
}
curr = curr->next;
table->iterOK = False;
while (curr) {
- if (cmp(hnode, curr) == 0) { // GEN!!!
+ if (hnode->key == curr->key && cmp(hnode, curr) == 0) { // GEN!!!
*prev_next_ptr = curr->next;
table->n_elements--;
return curr;
* when comparing the rest of the node, if the node data contains holes
between components, either the node memory should be fully initialised
(e.g. allocated using VG_(calloc)) or each component should be compared
- individually. */
+ individually.
+ Note that the cmp function is only called for elements that already
+ have keys that are equal. So, it is not needed for cmp to check for
+ key equality. */
extern void* VG_(HT_gen_lookup) ( const VgHashTable *table, const void* node,
HT_Cmp_t cmp );
extern void* VG_(HT_gen_remove) ( VgHashTable *table, const void* node,