cvs: ZendEngine2(PHP_5_3) / zend_hash.h

[email protected] ("Dmitry Stogov") Wed, 18 Mar 2009 09:48:55 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1237369735@cvsserver>
dmitry		Wed Mar 18 09:48:55 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /ZendEngine2	zend_hash.h 
  Log:
  Better fix for bug #45877 (smaller and faster)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.h?r1=1.78.2.2.2.2.2.9&r2=1.78.2.2.2.2.2.10&diff_format=u
Index: ZendEngine2/zend_hash.h
diff -u ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.9 ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.10
--- ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.9	Wed Mar 18 01:08:12 2009
+++ ZendEngine2/zend_hash.h	Wed Mar 18 09:48:55 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_hash.h,v 1.78.2.2.2.2.2.9 2009/03/18 01:08:12 mattwil Exp $ */
+/* $Id: zend_hash.h,v 1.78.2.2.2.2.2.10 2009/03/18 09:48:55 dmitry Exp $ */
 
 #ifndef ZEND_HASH_H
 #define ZEND_HASH_H
@@ -304,42 +304,37 @@
 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent)			\
 	zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
 
-
-#define ZEND_HANDLE_NUMERIC(key, length, func) {												\
-	register const char *tmp=key;																\
-																						\
-	if (*tmp=='-') {																	\
-		tmp++;																			\
-	}																					\
-	if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index */					\
-		const char *end=key+length-1;															\
-		long idx = end - tmp; /* temp var for remaining length (number of digits) */	\
-																						\
-		if (idx > MAX_LENGTH_OF_LONG - 1 || (*tmp++ == '0' && length > 2)) {			\
-			/* don't accept numbers too long or with leading zeros */					\
-			break;																		\
-		}																				\
-		while (tmp<end) {																\
-			if (!(*tmp>='0' && *tmp<='9')) {											\
-				break;																	\
-			}																			\
-			tmp++;																		\
-		}																				\
-		if (tmp==end && *tmp=='\0') { /* a numeric index */								\
-			if (idx == MAX_LENGTH_OF_LONG - 1) {										\
-				int cmp = strcmp(end - (MAX_LENGTH_OF_LONG - 1), long_min_digits);		\
-																						\
-				if (!(cmp < 0 || (cmp == 0 && *key == '-'))) {							\
-					break;																\
-				}																		\
-			}																			\
-																						\
-			idx = strtol(key, NULL, 10);												\
-			return func;																\
-		}																				\
-	} while (0);																		\
-}
-
+#define ZEND_HANDLE_NUMERIC(key, length, func) do {							\
+	register const char *tmp = key;											\
+	const char *end = key + length - 1;										\
+	long idx;																\
+																			\
+	if (*tmp == '-') {														\
+		tmp++;																\
+	}																		\
+	if ((*tmp >= '1' && *tmp <= '9' && (end - tmp) < MAX_LENGTH_OF_LONG) ||	\
+	    (*tmp == '0' && (end - tmp) == 1)) {								\
+		/* possibly a numeric index without leading zeroes */				\
+		idx = (*tmp++ - '0');												\
+		while (1) {															\
+			if (tmp == end && *tmp == '\0') { /* a numeric index */			\
+				if (*key == '-') {											\
+					idx = -idx;												\
+					if (idx > 0) { /* overflow */							\
+						break;												\
+					}														\
+				} else if (idx < 0) { /* overflow */						\
+					break;													\
+				}															\
+				return func;												\
+			} else if (*tmp >= '0' && *tmp <= '9') {						\
+				idx = (idx * 10) + (*tmp++ - '0');							\
+			} else {														\
+				break;														\
+			}																\
+		}																	\
+	}																		\
+} while (0)
 
 static inline int zend_symtable_update(HashTable *ht, const char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest)					\
 {
@@ -350,7 +345,7 @@
 
 static inline int zend_symtable_del(HashTable *ht, const char *arKey, uint nKeyLength)
 {
-	ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_del(ht, idx))
+	ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_del(ht, idx));
 	return zend_hash_del(ht, arKey, nKeyLength);
 }