- Allowed storing NULL pointers in HashTable
- Optimized zend_hash_reverse_apply()
This commit is contained in:
Dmitry Stogov 2006-04-07 10:06:21 +00:00
parent 8625b42162
commit 6624682dff

View File

@ -102,14 +102,14 @@ ZEND_API ulong zend_hash_func(char *arKey, uint nKeyLength)
#define UPDATE_DATA(ht, p, pData, nDataSize) \ #define UPDATE_DATA(ht, p, pData, nDataSize) \
if (nDataSize == sizeof(void*)) { \ if (nDataSize == sizeof(void*)) { \
if (!(p)->pDataPtr) { \ if ((p)->pData != &(p)->pDataPtr) { \
pefree_rel((p)->pData, (ht)->persistent); \ pefree_rel((p)->pData, (ht)->persistent); \
} \ } \
memcpy(&(p)->pDataPtr, pData, sizeof(void *)); \ memcpy(&(p)->pDataPtr, pData, sizeof(void *)); \
(p)->pData = &(p)->pDataPtr; \ (p)->pData = &(p)->pDataPtr; \
} else { \ } else { \
if ((p)->pDataPtr) { \ if ((p)->pData == &(p)->pDataPtr) { \
(p)->pData = (void *) pemalloc_rel(nDataSize, (ht)->persistent); \ (p)->pData = (void *) pemalloc_rel(nDataSize, (ht)->persistent); \
(p)->pDataPtr=NULL; \ (p)->pDataPtr=NULL; \
} else { \ } else { \
(p)->pData = (void *) perealloc_rel((p)->pData, nDataSize, (ht)->persistent); \ (p)->pData = (void *) perealloc_rel((p)->pData, nDataSize, (ht)->persistent); \
@ -123,9 +123,9 @@ ZEND_API ulong zend_hash_func(char *arKey, uint nKeyLength)
memcpy(&(p)->pDataPtr, pData, sizeof(void *)); \ memcpy(&(p)->pDataPtr, pData, sizeof(void *)); \
(p)->pData = &(p)->pDataPtr; \ (p)->pData = &(p)->pDataPtr; \
} else { \ } else { \
(p)->pData = (void *) pemalloc_rel(nDataSize, (ht)->persistent); \ (p)->pData = (void *) pemalloc_rel(nDataSize, (ht)->persistent);\
if (!(p)->pData) { \ if (!(p)->pData) { \
pefree_rel(p, (ht)->persistent); \ pefree_rel(p, (ht)->persistent); \
return FAILURE; \ return FAILURE; \
} \ } \
memcpy((p)->pData, pData, nDataSize); \ memcpy((p)->pData, pData, nDataSize); \
@ -491,7 +491,7 @@ ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLen
if (ht->pDestructor) { if (ht->pDestructor) {
ht->pDestructor(p->pData); ht->pDestructor(p->pData);
} }
if (!p->pDataPtr) { if (p->pData != &p->pDataPtr) {
pefree(p->pData, ht->persistent); pefree(p->pData, ht->persistent);
} }
pefree(p, ht->persistent); pefree(p, ht->persistent);
@ -520,7 +520,7 @@ ZEND_API void zend_hash_destroy(HashTable *ht)
if (ht->pDestructor) { if (ht->pDestructor) {
ht->pDestructor(q->pData); ht->pDestructor(q->pData);
} }
if (!q->pDataPtr && q->pData) { if (q->pData != &q->pDataPtr) {
pefree(q->pData, ht->persistent); pefree(q->pData, ht->persistent);
} }
pefree(q, ht->persistent); pefree(q, ht->persistent);
@ -546,7 +546,7 @@ ZEND_API void zend_hash_clean(HashTable *ht)
if (ht->pDestructor) { if (ht->pDestructor) {
ht->pDestructor(q->pData); ht->pDestructor(q->pData);
} }
if (!q->pDataPtr && q->pData) { if (q->pData != &q->pDataPtr) {
pefree(q->pData, ht->persistent); pefree(q->pData, ht->persistent);
} }
pefree(q, ht->persistent); pefree(q, ht->persistent);
@ -575,7 +575,7 @@ static Bucket *zend_hash_apply_deleter(HashTable *ht, Bucket *p)
if (ht->pDestructor) { if (ht->pDestructor) {
ht->pDestructor(p->pData); ht->pDestructor(p->pData);
} }
if (!p->pDataPtr) { if (p->pData != &p->pDataPtr) {
pefree(p->pData, ht->persistent); pefree(p->pData, ht->persistent);
} }
retval = p->pListNext; retval = p->pListNext;
@ -734,11 +734,7 @@ ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSR
q = p; q = p;
p = p->pListLast; p = p->pListLast;
if (result & ZEND_HASH_APPLY_REMOVE) { if (result & ZEND_HASH_APPLY_REMOVE) {
if (q->nKeyLength>0) { zend_hash_apply_deleter(ht, q);
zend_hash_del(ht, q->arKey, q->nKeyLength);
} else {
zend_hash_index_del(ht, q->h);
}
} }
if (result & ZEND_HASH_APPLY_STOP) { if (result & ZEND_HASH_APPLY_STOP) {
break; break;