Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61164 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93247 invoked from network); 12 Jul 2012 13:19:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2012 13:19:00 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 config.schlueters.de Received: from [217.114.211.66] ([217.114.211.66:54258] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/D8-46517-2CECEFF4 for ; Thu, 12 Jul 2012 09:18:59 -0400 Received: from [192.168.2.230] (ppp-188-174-38-89.dynamic.mnet-online.de [188.174.38.89]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id F365362804; Thu, 12 Jul 2012 15:18:54 +0200 (CEST) To: Jille Timmermans Cc: internals@lists.php.net In-Reply-To: <4FFEB86D.3080302@quis.cx> References: <4FFEB86D.3080302@quis.cx> Content-Type: text/plain; charset="UTF-8" Date: Thu, 12 Jul 2012 15:18:54 +0200 Message-ID: <1342099134.1440.9.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] array_shift() and reindexing From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Thu, 2012-07-12 at 13:43 +0200, 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. I haven't checked this, but is the difference only due to the re-hashing or also due to the fact that that array_shift() is taking the array by reference and therefore making a copy during the call if other cow-references (refcount>1, isref=0) exist? johanne