|
From: <sv...@va...> - 2015-05-20 15:08:21
|
Author: philippe
Date: Wed May 20 16:08:09 2015
New Revision: 15263
Log:
Have the hash table 'gen' functions comparing the key instead of the
cmp function.
Document this in the cmp function comment in pub_tool_hashtable.h
Modified:
trunk/coregrind/m_deduppoolalloc.c
trunk/coregrind/m_hashtable.c
trunk/include/pub_tool_hashtable.h
Modified: trunk/coregrind/m_deduppoolalloc.c
==============================================================================
--- trunk/coregrind/m_deduppoolalloc.c (original)
+++ trunk/coregrind/m_deduppoolalloc.c Wed May 20 16:08:09 2015
@@ -177,16 +177,19 @@
}
}
+/* 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;
Modified: trunk/coregrind/m_hashtable.c
==============================================================================
--- trunk/coregrind/m_hashtable.c (original)
+++ trunk/coregrind/m_hashtable.c Wed May 20 16:08:09 2015
@@ -179,7 +179,7 @@
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;
@@ -222,7 +222,7 @@
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;
Modified: trunk/include/pub_tool_hashtable.h
==============================================================================
--- trunk/include/pub_tool_hashtable.h (original)
+++ trunk/include/pub_tool_hashtable.h Wed May 20 16:08:09 2015
@@ -84,7 +84,10 @@
* 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,
|