mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Avoid modulo operation in loop in array_chunk
For this benchmark: ```php $length = 25; for ($i=0;$i<1000;$i++) array_chunk(range(0, 10000), $length); ``` On an i7-4790, length=25 speeds up by 1.8x and length=1 by 1.27x. On an i7-1185G7, length=25 speeds up by 1.08x and length=1 by 1.02x.
This commit is contained in:
parent
1eadf553f1
commit
4762d46427
1 changed files with 2 additions and 1 deletions
|
@ -7046,9 +7046,10 @@ PHP_FUNCTION(array_chunk)
|
||||||
|
|
||||||
/* If reached the chunk size, add it to the result array, and reset the
|
/* If reached the chunk size, add it to the result array, and reset the
|
||||||
* pointer. */
|
* pointer. */
|
||||||
if (!(++current % size)) {
|
if (++current == size) {
|
||||||
add_next_index_zval(return_value, &chunk);
|
add_next_index_zval(return_value, &chunk);
|
||||||
ZVAL_UNDEF(&chunk);
|
ZVAL_UNDEF(&chunk);
|
||||||
|
current = 0;
|
||||||
}
|
}
|
||||||
} ZEND_HASH_FOREACH_END();
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue