Re: array_shift() and reindexing

From: Date: Thu, 12 Jul 2012 13:02:11 +0000
Subject: Re: array_shift() and reindexing
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-61163@lists.php.net to get a copy of this message
It seems 7-8 times slower than array_shift() and that is even without a way to fetch the first value. I tried $array = array_slice($array, 1) and $array = array_slice($array, 1, NULL, true); -- Jille Op 12-07-12 14:39, David Muir schreef:
What about replacing the existing array with array_slice? David On 12/07/2012, at 9:43 PM, Jille Timmermans <jille@quis.cx> wrote:
Hello, array_shift() currently reindexes the array after shifting one element. The reindexing has quite some impact on it's performance. I would like to suggest an extra parameter to array_shift() which can be used to prevent reindexing. From a few quick (and sloppy!) tests I get these results: reset($array); list($key, $value) = each($array); unset($array[$key]); is ~50-150 times faster than array_shift(). Calling array_reverse() and using array_pop() is ~2000-5000 times faster. If you agree this would be an useful addition I will create a patch. -- Jille -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#61163) next »