cvs: ZendEngine2 / zend_hash.c zend_hash.h

From: Date: Wed, 18 Mar 2009 09:49:07 +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-7466@lists.php.net to get a copy of this message
dmitry Wed Mar 18 09:49:07 2009 UTC Modified files: /ZendEngine2 zend_hash.c zend_hash.h Log: Better fix for bug #45877 (smaller and faster) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.c?r1=1.161&r2=1.162&diff_format=u Index: ZendEngine2/zend_hash.c diff -u ZendEngine2/zend_hash.c:1.161 ZendEngine2/zend_hash.c:1.162 --- ZendEngine2/zend_hash.c:1.161 Wed Dec 31 11:12:29 2008 +++ ZendEngine2/zend_hash.c Wed Mar 18 09:49:07 2009 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_hash.c,v 1.161 2008/12/31 11:12:29 sebastian Exp $ */ +/* $Id: zend_hash.c,v 1.162 2009/03/18 09:49:07 dmitry Exp $ */ #include "zend.h" #include "zend_operators.h" @@ -2071,7 +2071,7 @@ ZEND_API 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); } /* }}} */ @@ -2106,7 +2106,7 @@ ZEND_API int zend_ascii_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_ascii_hash_del(ht, arKey, nKeyLength); } /* }}} */ @@ -2134,7 +2134,7 @@ ZEND_API int zend_rt_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_rt_hash_del(ht, arKey, nKeyLength); } /* }}} */ @@ -2162,7 +2162,7 @@ ZEND_API int zend_utf8_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_utf8_hash_del(ht, arKey, nKeyLength); } /* }}} */ http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.h?r1=1.99&r2=1.100&diff_format=u Index: ZendEngine2/zend_hash.h diff -u ZendEngine2/zend_hash.h:1.99 ZendEngine2/zend_hash.h:1.100 --- ZendEngine2/zend_hash.h:1.99 Wed Mar 18 01:06:30 2009 +++ ZendEngine2/zend_hash.h Wed Mar 18 09:49:07 2009 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_hash.h,v 1.99 2009/03/18 01:06:30 mattwil Exp $ */ +/* $Id: zend_hash.h,v 1.100 2009/03/18 09:49:07 dmitry Exp $ */ #ifndef ZEND_HASH_H #define ZEND_HASH_H @@ -398,75 +398,69 @@ ZEND_API int zend_u_symtable_update_current_key(HashTable *ht, zend_uchar type, zstr arKey, uint nKeyLength, int mode); /* {{{ ZEND_HANDLE_*_NUMERIC macros */ -#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_U_NUMERIC(key, length, func) { \ - register UChar *tmp=key; \ - \ - if (*tmp==0x2D /*'-'*/) { \ - tmp++; \ - } \ - if ((*tmp>=0x30 /*'0'*/ && *tmp<=0x39 /*'9'*/)) do { /* possibly a numeric index */ \ - UChar *end=key+length-1; \ - long idx = end - tmp; /* temp var for remaining length (number of digits) */ \ - \ - if (idx > MAX_LENGTH_OF_LONG - 1 || (*tmp++ == 0x30 && length > 2)) { \ - /* don't accept numbers too long or with leading zeros */ \ - break; \ - } \ - while (tmp<end) { \ - if (!(*tmp>=0x30 /*'0'*/ && *tmp<=0x39 /*'9'*/)) { \ - break; \ - } \ - tmp++; \ - } \ - if (tmp==end && *tmp==0) { /* a numeric index */ \ - if (idx == MAX_LENGTH_OF_LONG - 1) { \ - int cmp = zend_cmp_unicode_and_literal(end - (MAX_LENGTH_OF_LONG - 1), idx, long_min_digits, idx); \ - \ - if (!(cmp < 0 || (cmp == 0 && *key == 0x2D /*'-'*/))) { \ - break; \ - } \ - } \ - \ - idx = zend_u_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) + +#define ZEND_HANDLE_U_NUMERIC(key, length, func) do { \ + register const UChar *tmp = key; \ + const UChar *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) /* }}} */ #endif /* ZEND_HASH_H */

« previous php.zend-engine.cvs (#7466) next »