Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61163 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91122 invoked from network); 12 Jul 2012 13:02:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2012 13:02:25 -0000 Authentication-Results: pb1.pair.com header.from=jille@quis.cx; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jille@quis.cx; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain quis.cx from 82.94.237.14 cause and error) X-PHP-List-Original-Sender: jille@quis.cx X-Host-Fingerprint: 82.94.237.14 mulgore.hexon-is.nl Received: from [82.94.237.14] ([82.94.237.14:49012] helo=mulgore.hexon-is.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/78-46517-CDACEFF4 for ; Thu, 12 Jul 2012 09:02:25 -0400 Received: from adidas.hexon-nijmegen.nl (gw.hexon-nijmegen.nl [82.93.241.107]) by mulgore.hexon-is.nl (8.14.3/8.14.3) with ESMTP id q6CD2Cp9006759; Thu, 12 Jul 2012 15:02:13 +0200 Received: from [10.0.0.137] (pcjille.hexon-nijmegen.nl [10.0.0.137]) by adidas.hexon-nijmegen.nl (8.14.3/8.14.3) with ESMTP id q6CD2ChI031517; Thu, 12 Jul 2012 15:02:12 +0200 Message-ID: <4FFECAD3.4000403@quis.cx> Date: Thu, 12 Jul 2012 15:02:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: David Muir CC: "internals@lists.php.net" References: <4FFEB86D.3080302@quis.cx> <43D27342-52D3-4D51-A574-F7A5075164C4@gmail.com> In-Reply-To: <43D27342-52D3-4D51-A574-F7A5075164C4@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Hexon-MailScanner-Information: Please contact the ISP for more information X-Hexon-MailScanner-ID: q6CD2Cp9006759 X-Hexon-MailScanner: Found to be clean X-Hexon-MailScanner-From: jille@quis.cx X-Hexon-MailScanner-Watermark: 1342702933.63964@wxE5TTUWWP5wtTNjVLEIug Subject: Re: [PHP-DEV] array_shift() and reindexing From: jille@quis.cx (Jille Timmermans) 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 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 >>