summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-04-08 11:17:17 +0200
committerNikita Popov <nikic@php.net>2014-04-09 12:31:21 +0200
commit1aa8719e32663fbfcad9668364fbac0bc415b678 (patch)
tree22285673a59fdcac958bee6b78ad204a3f650ed1 /ext/standard/array.c
parenteaf44ec397cc3286107166ce51bac03bf6bc8f83 (diff)
downloadphp-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.c19
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;
}