Re: cvs: php4 /ext/standard array.c
| From: | Andi Gutmans | Date: | Sat, 03 Aug 2002 09:19:32 +0000 |
| Subject: | Re: cvs: php4 /ext/standard array.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-13098@lists.php.net to get a copy of this message | ||
At 04:38 AM 8/1/2002 +0000, Brad LaFountain wrote:
Brad, I think it kind of sucks to have code which manipulates the hash directly in PHP. If this is really needed then it should be made a function in zend_hash.* Andirodif_bl Thu Aug 1 00:38:11 2002 EDTModified files:/php4/ext/standard array.cLog: made array_shift re-index like it did before previous fix Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.174 php4/ext/standard/array.c:1.175--- php4/ext/standard/array.c:1.174 Wed Jul 31 09:49:50 2002+++ php4/ext/standard/array.c Thu Aug 1 00:38:11 2002 @@ -21,7 +21,7 @@+----------------------------------------------------------------------+*/ -/* $Id: array.c,v 1.174 2002/07/31 13:49:50 sniper Exp $ */ +/* $Id: array.c,v 1.175 2002/08/01 04:38:11 rodif_bl Exp $ */ #include "php.h" #include "php_ini.h" @@ -1661,8 +1661,9 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end) {zval **stack, /* Input stack */ - **val; /* Value to be popped */ - HashTable *new_hash; /* New stack */ + **val; /* Value to be popped */ + char *key = NULL; + int key_len, index;/* Get the arguments and do error-checking */ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &stack) == FAILURE) {@@ -1689,13 +1690,27 @@INIT_PZVAL(return_value);/* Delete the first or last value */ - new_hash = php_splice(Z_ARRVAL_PP(stack), (off_the_end) ? -1 : 0, 1, NULL, 0, NULL); - zend_hash_destroy(Z_ARRVAL_PP(stack)); - efree(Z_ARRVAL_PP(stack)); - Z_ARRVAL_PP(stack) = new_hash; + zend_hash_get_current_key_ex(Z_ARRVAL_PP(stack), &key, &key_len, &index, 0, NULL); + zend_hash_del_key_or_index(Z_ARRVAL_PP(stack), key, key_len, index, (key) ? HASH_DEL_KEY : HASH_DEL_INDEX);++ // If we did a shift... re-index like it did before + if(!off_the_end) { + HANDLE_BLOCK_INTERRUPTIONS(); + { + int k = 0; + Bucket *p = Z_ARRVAL_PP(stack)->pListHead; + while (p != NULL) { + if (p->nKeyLength == 0) + p->h = k++; + p = p->pListNext; + } + Z_ARRVAL_PP(stack)->nNextFreeElement = k+1; + zend_hash_rehash(Z_ARRVAL_PP(stack)); + } + HANDLE_UNBLOCK_INTERRUPTIONS(); + }