Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94883 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3178 invoked from network); 6 Aug 2016 12:14:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Aug 2016 12:14:06 -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 89.163.237.165 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 89.163.237.165 unknown Received: from [89.163.237.165] ([89.163.237.165:39876] helo=mx.zeyos.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/39-33134-B84D5A75 for ; Sat, 06 Aug 2016 08:14:05 -0400 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id 480605FA95 for ; Sat, 6 Aug 2016 14:14:01 +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=1470485641; x=1471349642; bh=zAbFANZDF/WPhrsQaF1q9e0DtHe1ekGy0vhsqis/bt4=; b= VujYc9zZOJciDJXs2hSu0p1GqVyNq7xoYC5KId1bXjiyRCLdvC0fuyguBdk6M6+9 aHzPfVwc9A8K6qi/UAWNsN8HEw8oc3gxqfbu/fSwoVARYyBUXiWmblpqzP8dEySn NY6YHMx5EO0yQVGlo/uTP5f8q2tPWsqGOBrXcO80iYQ= 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 SCXQzxqKJBMX for ; Sat, 6 Aug 2016 14:14:01 +0200 (CEST) Received: from 127.0.0.1 (srv32.dedicated.server-hosting.expert [89.163.135.32]) by mx.zeyos.com (Postfix) with ESMTPSA id E2C095FA93; Sat, 6 Aug 2016 14:14:00 +0200 (CEST) Date: Sat, 06 Aug 2016 14:14:00 +0200 To: PHP Internals Cc: Xinchen Hui MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20160806121401.480605FA95@mx.zeyos.com> Subject: Re: [PHP-DEV] More packed hash optimizations in array.c From: ben.coutu@zeyos.com (Benjamin Coutu) Hi Xinchen, There is still a way we could make this work, if we'd simply check for nNum= Used =3D=3D nNumOfElements as well. Because a packed array with nNumUsed eq= ual to nNumOfElements must be consecutively indexed from zero onward withou= t any gaps (no IS_UNDEF). I therefore propose to change array_slice to use: if ((Z_ARRVAL_P(input)->u.flags & HASH_FLAG_PACKED) && (!preserve_keys || (= offset =3D=3D 0 && Z_ARRVAL_P(input)->nNumUsed =3D=3D Z_ARRVAL_P(input)->nN= umOfElements))) I think the additional check is well worth it as it is not costly per se an= d will only ever be performed for the case of array_slice($packed_array, 0,= ..., true). It won't slow down the more common cases of array_slice($packe= d_array, ..., false) or array_slice($hash_array, ..., true/false). That way we can preserve the packed charactersitic even if the input array = was channelled through array_slice with preserved_keys=3Dtrue, which is not= that uncommon given that many APIs use wrappers around array_slice with th= e preserve_keys option precautiously set to true. Let me know what you think. Thanks, Benjamin