diff options
author | Nikita Popov <nikic@php.net> | 2014-04-08 11:17:17 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-04-09 12:31:21 +0200 |
commit | 1aa8719e32663fbfcad9668364fbac0bc415b678 (patch) | |
tree | 22285673a59fdcac958bee6b78ad204a3f650ed1 /ext/standard/array.c | |
parent | eaf44ec397cc3286107166ce51bac03bf6bc8f83 (diff) | |
download | php-git-1aa8719e32663fbfcad9668364fbac0bc415b678.tar.gz |
Add zend_hash_reindex
The implementation differs from the original in array.c in that it
rehashes the hashtable in the same loop. This is approximately two
times faster (not counting the rare case of a purely associative
array).
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index e84e019690..90ef8e47b8 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1975,24 +1975,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) { - unsigned int k = 0; - int should_rehash = 0; - Bucket *p = Z_ARRVAL_P(stack)->pListHead; - while (p != NULL) { - if (p->nKeyLength == 0) { - if (p->h != k) { - p->h = k++; - should_rehash = 1; - } else { - k++; - } - } - p = p->pListNext; - } - Z_ARRVAL_P(stack)->nNextFreeElement = k; - if (should_rehash) { - zend_hash_rehash(Z_ARRVAL_P(stack)); - } + zend_hash_reindex(Z_ARRVAL_P(stack)); } else if (!key_len && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) { Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1; } |