Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111774 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84077 invoked from network); 2 Sep 2020 04:11:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2020 04:11:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5694E1804D8 for ; Tue, 1 Sep 2020 20:15:50 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 1 Sep 2020 20:15:49 -0700 (PDT) Received: by mail-qt1-f172.google.com with SMTP id b3so2617754qtg.13 for ; Tue, 01 Sep 2020 20:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:message-id:date:cc:to; bh=RgulbzVwenYh0xyug/cP8st1YlftMTSjPoYrCpbpFq0=; b=jFe+j6DvlfWpdLBv+7c3zcvJFZp/4IdBCBbrXztNtax0yD1oxRaSLg4rr10KJEeqce oiFTF+D4ivxybnclzmBCwlPtTC+y83qgSK2v08JEfE52+DYbbEQOqMVTZFXcn0Sh+Xla es71sT/YtHJNSqpddATo5fZ5DUvcMOQX5xZYfG1/mkIAG6NczsCGmewiaX4gEantb0wx Q5nQCd3ojQqDhfHZVkvlDwxkTGQlczsc+QvfxajmeGD0/ferlfZ3dVUdw/i/QMvLmAPx pQJV9Po/Nd13UYmuOkd9Q3SNiaKIsGZ+D9i0rrym19Wf76ALsOSawTSXTC2r00G0q8s/ nIZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:cc:to; bh=RgulbzVwenYh0xyug/cP8st1YlftMTSjPoYrCpbpFq0=; b=Ws/TFOh9LqDLVlroBD+CNd3yXeksmAitqxwsRXWz/y/9uRWpilZjdkFedZeLPwWHwh FohekK3lvR5bWocOTjD0Vmhm/Clndk10HV3CulQ/QZDJwcXB/pQmM/u0nanWB2naLVt5 CgbwAdfGEBHDB2ffgs7isc3FqV+mu1XPJmBaZWuaCf9QfL12YCGMOyzKTwRtX/ILh3xq Jzmp0LdOsD+uKSDMwroPQFLS+SXokpg+a2p4jRGG5H5tlj79dYwu+6LwLkgxLIa1k2kF QTxPp8wvAFcTFktKD7KdOmksSJnRGgf+vvn5x9tbgg3SHize9k47JBpgV/PWm7rxtP36 9VeA== X-Gm-Message-State: AOAM5334aBmX7YtZWciyVbPFpzqi1lAKqxtHOacLBS7Ff2zxMm/HTpeu tetSR2CT7gjNxdYFgnbx0nFingm2dylHM40N X-Google-Smtp-Source: ABdhPJwl5cRPhWNpqln3lHcOhc4mbYC+H3D5XuV9RUEa5favGaXMn1ieoxFA1jpqlVy8bJOLBFU7CA== X-Received: by 2002:ac8:1b3d:: with SMTP id y58mr4883373qtj.10.1599016546476; Tue, 01 Sep 2020 20:15:46 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:6572:ebee:6047:150d? ([2601:c0:c680:5cc0:6572:ebee:6047:150d]) by smtp.gmail.com with ESMTPSA id g37sm3860746qtk.76.2020.09.01.20.15.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2020 20:15:45 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_1009EBD9-A59E-423B-8FB4-C234A4AD6DB6" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Message-ID: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> Date: Tue, 1 Sep 2020 23:15:43 -0400 Cc: PHP internals To: John Bafford X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Draft RFC: foreach iteration of keys without values From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_1009EBD9-A59E-423B-8FB4-C234A4AD6DB6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 This is a new thread for John Bafford's RFC which he mentioned on = another thread, see below: https://wiki.php.net/rfc/foreach_void = =20 > On Aug 31, 2020, at 5:50 PM, John Bafford wrote: >=20 > Hi Riikka, >=20 >> On Aug 31, 2020, at 14:13, Riikka Kalliom=C3=A4ki = wrote: >>=20 >> A common pattern that I've seen that could dearly use PHP internal >> optimization, if possible, would be: >>=20 >> foreach (array_keys($array) as $key) { >> } >=20 > I have a draft RFC (https://wiki.php.net/rfc/foreach_void) and patch = (https://github.com/jbafford/php-src/tree/foreachvoid against php 7.0, I = think) that helps with this, by allowing the following syntax: >=20 > foreach($iterable as $key =3D> void) { ... } >=20 > This would iterate over the keys of the iterable, and does not = retrieve the values at all. >=20 > In theory, this should be a general performance win any time one needs = to iterate over only the keys of an iterable, because it does not = require the use of an O(n) iteration and building of the array that = array_keys() would, plus it works on non-array types (such as generators = or iterators). It also is more performant than foreach($iterable as $key = =3D> $_) {}, because it omits the opcode that instructs the engine to = retrieve the value. (Presumably, a future direction could include using = this request to inform generators or iterators to only return keys, and = not values, which could further improve performance, especially if value = generation is expensive. But that is out of scope for this RFC.) >=20 > If this is something we'd like for PHP 8.1 and there are no major = objections to the idea, then after 8.0 is released, I can move the RFC = out of Draft and into Under Discussion, and presuming a vote passes, = I'll update the patch as necessary to work against 8.0. But my time is = limited and I'm not willing to put further time into the code unless an = RFC vote passes. >=20 > Thoughts anyone? +1 from me. =20 BTW, your RFC says "Next PHP 7.x" for Proposed Version; might need to = update that? -Mike= --Apple-Mail=_1009EBD9-A59E-423B-8FB4-C234A4AD6DB6--