mirror of
https://github.com/php/php-src.git
synced 2024-12-04 23:34:25 +08:00
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.
This commit is contained in:
parent
94040a28ce
commit
8c2dbd5f0f
@ -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 we did a shift... re-index like it did before */
|
||||||
if (!off_the_end) {
|
if (!off_the_end) {
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
int should_rehash = 0;
|
||||||
Bucket *p = Z_ARRVAL_PP(stack)->pListHead;
|
Bucket *p = Z_ARRVAL_PP(stack)->pListHead;
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
if (p->nKeyLength == 0) {
|
if (p->nKeyLength == 0) {
|
||||||
p->h = k++;
|
if (p->h != k) {
|
||||||
|
p->h = k++;
|
||||||
|
should_rehash = 1;
|
||||||
|
} else {
|
||||||
|
k++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = p->pListNext;
|
p = p->pListNext;
|
||||||
}
|
}
|
||||||
Z_ARRVAL_PP(stack)->nNextFreeElement = k;
|
Z_ARRVAL_PP(stack)->nNextFreeElement = k;
|
||||||
if (k) {
|
if (should_rehash) {
|
||||||
zend_hash_rehash(Z_ARRVAL_PP(stack));
|
zend_hash_rehash(Z_ARRVAL_PP(stack));
|
||||||
}
|
}
|
||||||
} else if (!key_len) {
|
} else if (!key_len) {
|
||||||
|
Loading…
Reference in New Issue
Block a user