Repository : ssh://git@open-mesh.org/batman-adv
On branch : next
commit 803bae00f0ed480ed4be0b28792847162b0b91bc Author: Simon Wunderlich simon.wunderlich@s2003.tu-chemnitz.de Date: Wed Nov 14 10:53:48 2012 +0100
batman-adv: pass value in batadv_hash_bytes
Passing the hash value by reference creates unneeded overhead. Pass by value instead.
Reported-by: David Miller davem@davemloft.net Signed-off-by: Simon Wunderlich siwu@hrz.tu-chemnitz.de Signed-off-by: Marek Lindner lindner_marek@yahoo.de
803bae00f0ed480ed4be0b28792847162b0b91bc bridge_loop_avoidance.c | 8 ++++---- hash.h | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index b6da6ae..fc56ea2 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -43,8 +43,8 @@ static inline uint32_t batadv_choose_claim(const void *data, uint32_t size) struct batadv_claim *claim = (struct batadv_claim *)data; uint32_t hash = 0;
- batadv_hash_bytes(&hash, &claim->addr, sizeof(claim->addr)); - batadv_hash_bytes(&hash, &claim->vid, sizeof(claim->vid)); + hash = batadv_hash_bytes(hash, &claim->addr, sizeof(claim->addr)); + hash = batadv_hash_bytes(hash, &claim->vid, sizeof(claim->vid));
hash += (hash << 3); hash ^= (hash >> 11); @@ -60,8 +60,8 @@ static inline uint32_t batadv_choose_backbone_gw(const void *data, struct batadv_claim *claim = (struct batadv_claim *)data; uint32_t hash = 0;
- batadv_hash_bytes(&hash, &claim->addr, sizeof(claim->addr)); - batadv_hash_bytes(&hash, &claim->vid, sizeof(claim->vid)); + hash = batadv_hash_bytes(hash, &claim->addr, sizeof(claim->addr)); + hash = batadv_hash_bytes(hash, &claim->vid, sizeof(claim->vid));
hash += (hash << 3); hash ^= (hash >> 11); diff --git a/hash.h b/hash.h index f173427..e053339 100644 --- a/hash.h +++ b/hash.h @@ -86,17 +86,21 @@ static inline void batadv_hash_delete(struct batadv_hashtable *hash, * @hash: previous hash value * @data: data to be hashed * @size: number of bytes to be hashed + * + * Returns the new hash value. */ -static inline void batadv_hash_bytes(uint32_t *hash, void *data, uint32_t size) +static inline uint32_t batadv_hash_bytes(uint32_t hash, void *data, + uint32_t size) { const unsigned char *key = data; int i;
for (i = 0; i < size; i++) { - *hash += key[i]; - *hash += (*hash << 10); - *hash ^= (*hash >> 6); + hash += key[i]; + hash += (hash << 10); + hash ^= (hash >> 6); } + return hash; }
/**