summaryrefslogtreecommitdiffstats
path: root/drivers/staging/batman-adv/hash.h
diff options
context:
space:
mode:
authorSven Eckelmann <sven.eckelmann@gmx.de>2010-11-22 00:55:56 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2010-11-29 11:09:12 -0800
commit51f3d8a27c1a1ac6aced25ea93fc5c0520e9256c (patch)
tree1e0c1335745d82561754a82d6649c6cb255712e8 /drivers/staging/batman-adv/hash.h
parent1341a00ad356dfb21978ce4e5e979024558042d2 (diff)
Staging: batman-adv: Remove hashdata_compare_cb from hash
Function pointers cannot be inlined by a compiler and thus always has the overhead of an call. hashdata_compare_cb's are one of the most often called function pointers and its overhead must kept relative low. As first step, every function which uses this function pointer takes it as parameter instead of storing it inside the hash abstraction structure. This not generate any performance gain right now. The called functions must also be able to be inlined by the calling functions to enable inlining of the function pointer. Reported-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/batman-adv/hash.h')
-rw-r--r--drivers/staging/batman-adv/hash.h23
1 files changed, 12 insertions, 11 deletions
diff --git a/drivers/staging/batman-adv/hash.h b/drivers/staging/batman-adv/hash.h
index 2c8e1762389..742277ea980 100644
--- a/drivers/staging/batman-adv/hash.h
+++ b/drivers/staging/batman-adv/hash.h
@@ -27,7 +27,10 @@
.prev_bucket = NULL, \
.first_bucket = NULL }
-
+/* callback to a compare function. should
+ * compare 2 element datas for their keys,
+ * return 0 if same and not 0 if not
+ * same */
typedef int (*hashdata_compare_cb)(void *, void *);
typedef int (*hashdata_choose_cb)(void *, int);
typedef void (*hashdata_free_cb)(void *, void *);
@@ -48,18 +51,13 @@ struct hashtable_t {
struct element_t **table; /* the hashtable itself, with the buckets */
int elements; /* number of elements registered */
int size; /* size of hashtable */
- hashdata_compare_cb compare;/* callback to a compare function. should
- * compare 2 element datas for their keys,
- * return 0 if same and not 0 if not
- * same */
hashdata_choose_cb choose; /* the hashfunction, should return an index
* based on the key in the data of the first
* argument and the size the second */
};
/* allocates and clears the hash */
-struct hashtable_t *hash_new(int size, hashdata_compare_cb compare,
- hashdata_choose_cb choose);
+struct hashtable_t *hash_new(int size, hashdata_choose_cb choose);
/* remove bucket (this might be used in hash_iterate() if you already found the
* bucket you want to delete and don't need the overhead to find it again with
@@ -76,21 +74,24 @@ void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb, void *arg);
void hash_destroy(struct hashtable_t *hash);
/* adds data to the hashtable. returns 0 on success, -1 on error */
-int hash_add(struct hashtable_t *hash, void *data);
+int hash_add(struct hashtable_t *hash, hashdata_compare_cb compare, void *data);
/* removes data from hash, if found. returns pointer do data on success, so you
* can remove the used structure yourself, or NULL on error . data could be the
* structure you use with just the key filled, we just need the key for
* comparing. */
-void *hash_remove(struct hashtable_t *hash, void *data);
+void *hash_remove(struct hashtable_t *hash, hashdata_compare_cb compare,
+ void *data);
/* finds data, based on the key in keydata. returns the found data on success,
* or NULL on error */
-void *hash_find(struct hashtable_t *hash, void *keydata);
+void *hash_find(struct hashtable_t *hash, hashdata_compare_cb compare,
+ void *keydata);
/* resize the hash, returns the pointer to the new hash or NULL on
* error. removes the old hash on success */
-struct hashtable_t *hash_resize(struct hashtable_t *hash, int size);
+struct hashtable_t *hash_resize(struct hashtable_t *hash,
+ hashdata_compare_cb compare, int size);
/* iterate though the hash. first element is selected with iter_in NULL. use
* the returned iterator to access the elements until hash_it_t returns NULL. */