From: Andrei Zmievski Date: Wed, 15 Mar 2000 16:25:59 +0000 (+0000) Subject: Make zend_hash_move_forward()/zenv_hash_move_backwards() a little smarter. X-Git-Tag: PHP-4.0-RC1~125 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee286febe78a19c7e4f825f033380c454123c0cd;p=php Make zend_hash_move_forward()/zenv_hash_move_backwards() a little smarter. --- diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index ded362ec72..a72778b6e1 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -918,26 +918,30 @@ ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos } -ZEND_API void zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos) +ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos) { + HashPosition *current = pos ? pos : &ht->pInternalPointer; + IS_CONSISTENT(ht); - if (pos) { - *pos = (*pos)->pListNext; - } else if (ht->pInternalPointer) { - ht->pInternalPointer = ht->pInternalPointer->pListNext; - } + if (*current) { + *current = (*current)->pListNext; + return SUCCESS; + } else + return FAILURE; } -ZEND_API void zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos) +ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos) { + HashPosition *current = pos ? pos : &ht->pInternalPointer; + IS_CONSISTENT(ht); - if (pos) { - *pos = (*pos)->pListLast; - } else if (ht->pInternalPointer) { - ht->pInternalPointer = ht->pInternalPointer->pListLast; - } + if (*current) { + *current = (*current)->pListLast; + return SUCCESS; + } else + return FAILURE; } diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index bef0f074b1..370b560017 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -148,8 +148,8 @@ ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h); ZEND_API ulong zend_hash_next_free_element(HashTable *ht); /* traversing */ -ZEND_API void zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos); -ZEND_API void zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos); +ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos); +ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos); ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *num_index, HashPosition *pos); ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos); ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);