Re: com php-src: Add only_integer_keys option to zend_hash_reindex: Zend/zend_hash.c Zend/zend_hash.h ext/standard/array.c
| From: | Pierre Joye | Date: | Wed, 09 Apr 2014 11:42:19 +0000 |
| Subject: | Re: com php-src: Add only_integer_keys option to zend_hash_reindex: Zend/zend_hash.c Zend/zend_hash.h ext/standard/array.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-76744@lists.php.net to get a copy of this message | ||
hi Nikita!
Please add a note to UPGRADING.INTERNALS (for other changes too=
Thanks for your work!
On Wed, Apr 9, 2014 at 12:31 PM, Nikita Popov <nikic@php.net> wrote:
> Commit: ad2ef3d97edab0d0ce034e65b7e3da1a38cc15dd
> Author: Nikita Popov <nikic@php.net> Wed, 9 Apr 2014 11:20:55 +0200
> Parents: f485c84a142a28c594dd7bcc3760a406dd4c5883
> Branches: PHP-5.6 master
>
> Link:
> http://git.php.net/?p=php-src.git;a=commitdiff;h=ad2ef3d97edab0d0ce034e65b7e3da1a38cc15dd
>
> Log:
> Add only_integer_keys option to zend_hash_reindex
>
> This allows to either do a full reindex, or only reindex the integer
> keys.
>
> Changed paths:
> M Zend/zend_hash.c
> M Zend/zend_hash.h
> M ext/standard/array.c
>
>
> Diff:
> diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
> index a33e872..3096313 100644
> --- a/Zend/zend_hash.c
> +++ b/Zend/zend_hash.c
> @@ -480,7 +480,7 @@ ZEND_API int zend_hash_rehash(HashTable *ht)
> return SUCCESS;
> }
>
> -ZEND_API void zend_hash_reindex(HashTable *ht) {
> +ZEND_API void zend_hash_reindex(HashTable *ht, zend_bool only_integer_keys) {
> Bucket *p;
> uint nIndex;
> ulong offset = 0;
> @@ -492,8 +492,9 @@ ZEND_API void zend_hash_reindex(HashTable *ht) {
>
> memset(ht->arBuckets, 0, ht->nTableSize * sizeof(Bucket *));
> for (p = ht->pListHead; p != NULL; p = p->pListNext) {
> - if (p->nKeyLength == 0) {
> + if (!only_integer_keys || p->nKeyLength == 0) {
> p->h = offset++;
> + p->nKeyLength = 0;
> }
>
> nIndex = p->h & ht->nTableMask;
> @@ -1353,7 +1354,7 @@ ZEND_API void _zend_hash_splice(HashTable *ht, uint nDataSize,
> copy_ctor_func_t
> ZEND_HASH_IF_FULL_DO_RESIZE(ht);
> }
>
> - zend_hash_reindex(ht);
> + zend_hash_reindex(ht, 1);
> }
> /* }}} */
>
> @@ -1403,15 +1404,7 @@ ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func,
> HANDLE_UNBLOCK_INTERRUPTIONS();
>
> if (renumber) {
> - p = ht->pListHead;
> - i=0;
> - while (p != NULL) {
> - p->nKeyLength = 0;
> - p->h = i++;
> - p = p->pListNext;
> - }
> - ht->nNextFreeElement = i;
> - zend_hash_rehash(ht);
> + zend_hash_reindex(ht, 0);
> }
> return SUCCESS;
> }
> diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
> index b07efc8..03f83df 100644
> --- a/Zend/zend_hash.h
> +++ b/Zend/zend_hash.h
> @@ -227,7 +227,7 @@ ZEND_API int zend_hash_minmax(const HashTable *ht, compare_func_t compar,
> int fl
> ZEND_API int zend_hash_num_elements(const HashTable *ht);
>
> ZEND_API int zend_hash_rehash(HashTable *ht);
> -ZEND_API void zend_hash_reindex(HashTable *ht);
> +ZEND_API void zend_hash_reindex(HashTable *ht, zend_bool only_integer_keys);
>
> ZEND_API void _zend_hash_splice(HashTable *ht, uint nDataSize, copy_ctor_func_t
> pCopyConstructor, uint offset, uint length, void **list, uint list_count, HashTable *removed
> ZEND_FILE_LINE_DC);
> #define zend_hash_splice(ht, nDataSize, pCopyConstructor, offset, length, list, list_count,
> removed) \
> diff --git a/ext/standard/array.c b/ext/standard/array.c
> index 7b2b1c5..6c3be81 100644
> --- a/ext/standard/array.c
> +++ b/ext/standard/array.c
> @@ -1786,13 +1786,7 @@ static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */
> }
> temp = hash->pListHead;
> j = 0;
> - while (temp != NULL) {
> - temp->nKeyLength = 0;
> - temp->h = j++;
> - temp = temp->pListNext;
> - }
> - hash->nNextFreeElement = n_elems;
> - zend_hash_rehash(hash);
> + zend_hash_reindex(hash, 0);
> HANDLE_UNBLOCK_INTERRUPTIONS();
>
> efree(elems);
> @@ -1897,7 +1891,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
>
> /* If we did a shift... re-index like it did before */
> if (!off_the_end) {
> - zend_hash_reindex(Z_ARRVAL_P(stack));
> + zend_hash_reindex(Z_ARRVAL_P(stack), 1);
> } else if (!key_len && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1)
> {
> Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement
> - 1;
> }
> @@ -3848,15 +3842,7 @@ PHP_FUNCTION(array_multisort)
> hash->pListTail = indirect[k][i];
> }
>
> - p = hash->pListHead;
> - k = 0;
> - while (p != NULL) {
> - if (p->nKeyLength == 0)
> - p->h = k++;
> - p = p->pListNext;
> - }
> - hash->nNextFreeElement = array_size;
> - zend_hash_rehash(hash);
> + zend_hash_reindex(hash, 1);
> }
> HANDLE_UNBLOCK_INTERRUPTIONS();
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Pierre
@pierrejoye | http://www.libgd.org