cvs: ZendEngine2 / zend_hash.c zend_hash.h
| From: | Zeev Suraski | Date: | Wed, 23 Jul 2003 08:56:34 +0000 |
| Subject: | cvs: ZendEngine2 / zend_hash.c zend_hash.h | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-1518@lists.php.net to get a copy of this message | ||
zeev Wed Jul 23 04:56:34 2003 EDT
Modified files:
/ZendEngine2 zend_hash.c zend_hash.h
Log:
Go back to ZE1-like code
Index: ZendEngine2/zend_hash.c
diff -u ZendEngine2/zend_hash.c:1.106 ZendEngine2/zend_hash.c:1.107
--- ZendEngine2/zend_hash.c:1.106 Tue Jul 22 12:06:07 2003
+++ ZendEngine2/zend_hash.c Wed Jul 23 04:56:34 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_hash.c,v 1.106 2003/07/22 16:06:07 zeev Exp $ */
+/* $Id: zend_hash.c,v 1.107 2003/07/23 08:56:34 zeev Exp $ */
#include "zend.h"
@@ -129,37 +129,6 @@
(p)->pDataPtr=NULL; \
}
-
-ZEND_API zend_bool zend_is_numeric_key(char *arKey, uint nKeyLength, long *val)
-{
- char *tmp = arKey;
-
- if ((*tmp>='0' && *tmp<='9')) { /* possibly a numeric index */
- char *end=tmp+nKeyLength-1;
- ulong idx;
-
- if (*tmp++=='0' && nKeyLength>2) { /* don't accept numbers with leading
zeros */
- return 0;
- }
-
- while (tmp<end) {
- if (!(*tmp>='0' && *tmp<='9')) {
- break;
- }
- tmp++;
- }
-
- if (tmp==end && *tmp=='\0') { /* a numeric index */
- idx = strtol(arKey, NULL, 10);
- if (idx!=LONG_MAX) {
- *val = idx;
- return 1;
- }
- }
- }
-
- return 0;
-}
ZEND_API int _zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t
pDestructor, zend_bool persistent ZEND_FILE_LINE_DC)
Index: ZendEngine2/zend_hash.h
diff -u ZendEngine2/zend_hash.h:1.71 ZendEngine2/zend_hash.h:1.72
--- ZendEngine2/zend_hash.h:1.71 Tue Jul 22 16:53:56 2003
+++ ZendEngine2/zend_hash.h Wed Jul 23 04:56:34 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_hash.h,v 1.71 2003/07/22 20:53:56 helly Exp $ */
+/* $Id: zend_hash.h,v 1.72 2003/07/23 08:56:34 zeev Exp $ */
#ifndef ZEND_HASH_H
#define ZEND_HASH_H
@@ -89,8 +89,6 @@
BEGIN_EXTERN_C()
-ZEND_API zend_bool zend_is_numeric_key(char *arKey, uint nKeyLength, long *val);
-
/* startup/shutdown */
ZEND_API int _zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t
pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
ZEND_API int _zend_hash_init_ex(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t
pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC);
@@ -286,51 +284,57 @@
zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
+#define HANDLE_NUMERIC(key, length, func) { \
+ register char *tmp=key; \
+ \
+ if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index
*/ \
+ char *end=tmp+length-1; \
+ ulong idx; \
+ \
+ if (*tmp++=='0' && length>2) { /* don't accept numbers with leading
zeros */ \
+ break; \
+ } \
+ while (tmp<end) { \
+ if (!(*tmp>='0' && *tmp<='9')) { \
+ break; \
+ } \
+ tmp++; \
+ } \
+ if (tmp==end && *tmp=='\0') { /* a numeric index */ \
+ idx = strtol(key, NULL, 10); \
+ if (idx!=LONG_MAX) { \
+ return func; \
+ } \
+ } \
+ } while (0); \
+}
+
+
static inline int zend_symtable_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData,
uint nDataSize, void **pDest) \
{
- long idx;
-
- if (zend_is_numeric_key(arKey, nKeyLength, &idx)) {
- return zend_hash_index_update(ht, idx, pData, nDataSize, pDest);
- } else {
- return zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest);
- }
+ HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update(ht, idx, pData, nDataSize, pDest));
+ return zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest);
}
static inline int zend_symtable_del(HashTable *ht, char *arKey, uint nKeyLength)
{
- long idx;
-
- if (zend_is_numeric_key(arKey, nKeyLength, &idx)) {
- return zend_hash_index_del(ht, idx);
- } else {
- return zend_hash_del(ht, arKey, nKeyLength);
- }
+ HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_del(ht, idx))
+ return zend_hash_del(ht, arKey, nKeyLength);
}
static inline int zend_symtable_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData)
{
- long idx;
-
- if (zend_is_numeric_key(arKey, nKeyLength, &idx)) {
- return zend_hash_index_find(ht, idx, pData);
- } else {
- return zend_hash_find(ht, arKey, nKeyLength, pData);
- }
+ HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_find(ht, idx, pData));
+ return zend_hash_find(ht, arKey, nKeyLength, pData);
}
static inline int zend_symtable_exists(HashTable *ht, char *arKey, uint nKeyLength)
{
- long idx;
-
- if (zend_is_numeric_key(arKey, nKeyLength, &idx)) {
- return zend_hash_index_exists(ht, idx);
- } else {
- return zend_hash_exists(ht, arKey, nKeyLength);
- }
+ HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_exists(ht, idx));
+ return zend_hash_exists(ht, arKey, nKeyLength);
}
#endif /* ZEND_HASH_H */