[asterisk-commits] nadi: branch nadi/trunk-cm r44333 - /team/nadi/trunk-cm/include/asterisk/hash.h

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 4 07:39:56 MST 2006


Author: nadi
Date: Wed Oct  4 09:39:54 2006
New Revision: 44333

URL: http://svn.digium.com/view/asterisk?rev=44333&view=rev
Log:
separated insert function

Modified:
    team/nadi/trunk-cm/include/asterisk/hash.h

Modified: team/nadi/trunk-cm/include/asterisk/hash.h
URL: http://svn.digium.com/view/asterisk/team/nadi/trunk-cm/include/asterisk/hash.h?rev=44333&r1=44332&r2=44333&view=diff
==============================================================================
--- team/nadi/trunk-cm/include/asterisk/hash.h (original)
+++ team/nadi/trunk-cm/include/asterisk/hash.h Wed Oct  4 09:39:54 2006
@@ -141,14 +141,19 @@
 	ast_mutex_unlock(&(hash)->_lock)
 
 
-#define __INSERT(hash, key, val, pos, prev)			\
-	hash->_data[pos]._key = key;					\
-	hash->_data[pos]._val = val;					\
-	hash->_data[pos]._used = 1;						\
-	if (prev > -1)									\
-		hash->_data[prev]._next = pos;				\
-	++hash->_length
-
+
+
+#define __TRY_INSERT(hash, key, val, pos, prev, re)	\
+	if (!hash->_data[pos]._used) {					\
+		hash->_data[pos]._key = key;				\
+		hash->_data[pos]._val = val;				\
+		hash->_data[pos]._used = 1;					\
+		if (prev > -1)								\
+			hash->_data[prev]._next = pos;			\
+		++hash->_length;							\
+		re = 0;										\
+		break;										\
+	}
 
 #define AST_HASH_INSERT_NOLOCK(hash, key, val)		\
 ({													\
@@ -156,36 +161,23 @@
  	int __end;										\
 	int __prev = -1;								\
  	int __re = -1;									\
-	int __goon = 0;									\
 	do {											\
-		if (!(hash)->_data[__pos]._used) {			\
- 			__INSERT((hash), (key), (val), __pos, __prev);	\
-			__re = 0;								\
-			break;									\
-		}											\
+		__TRY_INSERT((hash), (key), (val), __pos, __prev, __re);\
 		if ((hash)->_eq_f((hash)->_data[__pos]._key, (key)))	\
  			break;									\
  		__prev = __pos;								\
 		if ((hash)->_data[__pos]._next > -1)		\
 			__pos = (hash)->_data[__pos]._next;		\
 		else {										\
-			__goon = 1;								\
-			break;									\
+			__end = __pos;							\
+			__pos = (__pos + 1) % (hash)->_size;	\
+			do {									\
+				__TRY_INSERT((hash), (key), (val), __pos, __prev, __re);	\
+				__pos = (__pos + 1) % (hash)->_size;\
+			} while (__pos != __end);				\
+ 			break;									\
 		}											\
 	} while (1);									\
-	if (__goon) {									\
-		__end = __pos;								\
-		__pos = (__pos + 1) % (hash)->_size;		\
-		do {										\
-			if (!(hash)->_data[__pos]._used) {		\
-				__INSERT((hash), (key), (val), __pos, __prev);	\
-				__re = 0;							\
-				break;								\
-			}										\
-			__pos = (__pos + 1) % (hash)->_size;	\
-		}											\
-		while (__pos != __end);						\
-	}												\
 	__re;											\
 })
 



More information about the asterisk-commits mailing list