cvs: ZendEngine2(PHP_5_2) / zend_hash.c

From: Date: Fri, 03 Nov 2006 19:02:16 +0000
Subject: cvs: ZendEngine2(PHP_5_2) / zend_hash.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5364@lists.php.net to get a copy of this message
helly Fri Nov 3 19:02:16 2006 UTC Modified files: (Branch: PHP_5_2) /ZendEngine2 zend_hash.c Log: - MFH: Fixed bug #39320 http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.c?r1=1.121.2.4.2.1&r2=1.121.2.4.2.2&diff_format=u Index: ZendEngine2/zend_hash.c diff -u ZendEngine2/zend_hash.c:1.121.2.4.2.1 ZendEngine2/zend_hash.c:1.121.2.4.2.2 --- ZendEngine2/zend_hash.c:1.121.2.4.2.1 Thu Aug 24 09:42:35 2006 +++ ZendEngine2/zend_hash.c Fri Nov 3 19:02:16 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_hash.c,v 1.121.2.4.2.1 2006/08/24 09:42:35 dmitry Exp $ */ +/* $Id: zend_hash.c,v 1.121.2.4.2.2 2006/11/03 19:02:16 helly Exp $ */ #include "zend.h" @@ -647,12 +647,15 @@ SET_INCONSISTENT(HT_DESTROYED); } -/* This is used to selectively delete certain entries from a hashtable. - * destruct() receives the data and decides if the entry should be deleted - * or not +/* This is used to recurse elements and selectively delete certain entries + * from a hashtable. apply_func() receives the data and decides if the entry + * should be deleted or recursion should be stopped. The following three + * return codes are possible: + * ZEND_HASH_APPLY_KEEP - continue + * ZEND_HASH_APPLY_STOP - stop iteration + * ZEND_HASH_APPLY_REMOVE - delete the element, combineable with the former */ - ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC) { Bucket *p; @@ -662,11 +665,16 @@ HASH_PROTECT_RECURSION(ht); p = ht->pListHead; while (p != NULL) { - if (apply_func(p->pData TSRMLS_CC)) { + int result = apply_func(p->pData TSRMLS_CC); + + if (result & ZEND_HASH_APPLY_REMOVE) { p = zend_hash_apply_deleter(ht, p); } else { p = p->pListNext; } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } HASH_UNPROTECT_RECURSION(ht); } @@ -681,17 +689,22 @@ HASH_PROTECT_RECURSION(ht); p = ht->pListHead; while (p != NULL) { - if (apply_func(p->pData, argument TSRMLS_CC)) { + int result = apply_func(p->pData, argument TSRMLS_CC); + + if (result & ZEND_HASH_APPLY_REMOVE) { p = zend_hash_apply_deleter(ht, p); } else { p = p->pListNext; } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } HASH_UNPROTECT_RECURSION(ht); } -ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t destruct, int num_args, ...) +ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t apply_func, int num_args, ...) { Bucket *p; va_list args; @@ -703,15 +716,21 @@ p = ht->pListHead; while (p != NULL) { + int result; va_start(args, num_args); hash_key.arKey = p->arKey; hash_key.nKeyLength = p->nKeyLength; hash_key.h = p->h; - if (destruct(p->pData, num_args, args, &hash_key)) { + result = apply_func(p->pData, num_args, args, &hash_key); + + if (result & ZEND_HASH_APPLY_REMOVE) { p = zend_hash_apply_deleter(ht, p); } else { p = p->pListNext; } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } va_end(args); }

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