Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100964 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47800 invoked from network); 27 Oct 2017 12:12:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2017 12:12:30 -0000 Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zeyos.com designates 88.99.153.70 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 88.99.153.70 mx.zeyos.com Received: from [88.99.153.70] ([88.99.153.70:35390] helo=mx.zeyos.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/8D-28573-CA223F95 for ; Fri, 27 Oct 2017 08:12:29 -0400 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id 2AAC95FB05 for ; Fri, 27 Oct 2017 14:12:25 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :to:subject:subject:from:from:date:date; s=dkim; t=1509106345; x=1509970346; bh=u08UlHxrTCojWU6fgPaZ8/4AArYeXsZebvIdEBxuoS4=; b= WT+I3E8gGjDXN0tD1dwg4CZU8n70dlPcSMIU15H9DaC4/3y6nC059H6lB2nsqjt+ 1P9MVj48M5zn5aLIjClfSbMFyfNY3DM9nhEechgh5meiyxSjC8FuRVVa++KgwLXc hpwsDWc/fl/tnkzwfGQWywqeVlkGFEqoGvMNFh9AsCw= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CZGBDqmceX_N for ; Fri, 27 Oct 2017 14:12:25 +0200 (CEST) Received: from [81.171.8.203] (unknown [81.171.8.203]) by mx.zeyos.com (Postfix) with ESMTPSA id 142F65FA78; Fri, 27 Oct 2017 14:12:20 +0200 (CEST) Date: Fri, 27 Oct 2017 14:12:19 +0200 To: PHP Internals Cc: Dmitry Stogov , Nikita Popov MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20171027121225.2AAC95FB05@mx.zeyos.com> Subject: Apply substr() optimization to array_slice() From: ben.coutu@zeyos.com (Benjamin Coutu) Hello everyone,=0A=0APlease consider these two statements:=0A=0Asubstr($str= ing, 0, $length);=0Aarray_slice($array, 0, $length, true);=0A=0ACurrently, = with substr(), if $offset is zero and $length is smaller or equal to the or= iginal string length we just increase the reference count of the original s= tring and return it via RETURN_STR_COPY.=0AIn that case we completely save = the allocation of a new string.=0A=0ANow, array_slice() could be optimized = similarly, but currently (unless the resulting array is expected to be empt= y) we always create a new array no matter if we actually have to.=0AThe sam= e mechanism as used with substr() could be applied to array_slice(), given = that $offset is zero and of course only if $preserve_keys is true.=0A=0AA p= atch would look like this:=0A=0Aif (length <=3D num_in && offset =3D=3D 0 &= & preserve_keys) {=0A /* Copy the original array */=0A ZVAL_COPY(return_v= alue, input);=0A return;=0A}=0A=0AI'd appreciate if someone could commit t= his. Thanks.=0A=0ACheers,=0A=0ABenjamin=0A=0A-- =0A=0ABejamin Coutu=0Aben.c= outu@zeyos.com=0A=0AZeyOS, Inc.=0Ahttp://www.zeyos.com