summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2003-02-22 13:55:11 +0000
committerAndrey Hristov <andrey@php.net>2003-02-22 13:55:11 +0000
commit8c2dbd5f0fca49a0c10c2494d58509a2629af3a2 (patch)
tree4d1d67245993c7cc510a8bc5b7f1f4fcc665717f /ext/standard/array.c
parent94040a28ce4a90d00da051dbb1968d5e029ac396 (diff)
downloadphp-git-8c2dbd5f0fca49a0c10c2494d58509a2629af3a2.tar.gz
additional speedup for array_shift(). No need to rehash if the removed element's
key is not scalar and elements with scalar keys are already well numbered (sequentially from 0) for some reason. This is the case if the leading elements have no scalar indexes.
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index cf4f1889cf..2b1fead7c5 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -1858,15 +1858,21 @@ 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) {
int k = 0;
+ int should_rehash = 0;
Bucket *p = Z_ARRVAL_PP(stack)->pListHead;
while (p != NULL) {
if (p->nKeyLength == 0) {
- p->h = k++;
+ if (p->h != k) {
+ p->h = k++;
+ should_rehash = 1;
+ } else {
+ k++;
+ }
}
p = p->pListNext;
}
Z_ARRVAL_PP(stack)->nNextFreeElement = k;
- if (k) {
+ if (should_rehash) {
zend_hash_rehash(Z_ARRVAL_PP(stack));
}
} else if (!key_len) {