public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [RFC] batman-adv: pass value in batadv_hash_bytes
@ 2012-11-14  9:53 Simon Wunderlich
  2012-11-14 11:59 ` Antonio Quartulli
  2012-11-14 16:37 ` Marek Lindner
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Wunderlich @ 2012-11-14  9:53 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

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>
---
 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;
 }
 
 /**
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-14 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-14  9:53 [B.A.T.M.A.N.] [RFC] batman-adv: pass value in batadv_hash_bytes Simon Wunderlich
2012-11-14 11:59 ` Antonio Quartulli
2012-11-14 13:13   ` Marek Lindner
2012-11-14 13:21     ` Sven Eckelmann
2012-11-14 16:37 ` Marek Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox