Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111753 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37692 invoked from network); 31 Aug 2020 22:34:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Aug 2020 22:34:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 14F15180532 for ; Mon, 31 Aug 2020 14:39:25 -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,HTML_MESSAGE, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-mahalux.mvorisek.com (mail-mahalux.mvorisek.com [77.93.195.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 31 Aug 2020 14:39:23 -0700 (PDT) Received: from cf0436ab48a5 (10.228.0.212) by mail-mahalux.mvorisek.com (10.228.0.4) with Microsoft SMTP Server (TLS); Mon, 31 Aug 2020 23:39:19 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_d646f9189df85661bcc98d451ba5cfcb" Date: Mon, 31 Aug 2020 23:39:19 +0200 To: Max Semenik Cc: =?UTF-8?Q?Riikka_Kalliom=C3=A4ki?= , PHP internals In-Reply-To: References: <5330022558dfa7cbd154e3c765c509478fcb84084de8987274e24aa1ff017b85@mahalux.com> Message-ID: <9ea61347e65a08ee095b141d619c9bbf3615692e61d02a1e8d0e4d6eb1afd539@mahalux.com> X-Mailer: SAP NetWeaver 7.03 Subject: Re: [PHP-DEV] Request for couple memory optimized array improvements From: vorismi3@fel.cvut.cz (=?UTF-8?Q?Michael_Vo=C5=99=C3=AD=C5=A1ek_-_=C4=8CVUT_FEL?=) --=_d646f9189df85661bcc98d451ba5cfcb Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed I would highly prefer php optimalization for it. ArrayKeysIterator can not even used if the input is iterable instead of pure array. With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, Michael Voříšek On 31 Aug 2020 23:31, Max Semenik wrote: > On Mon, Aug 31, 2020 at 11:53 PM Michael Voříšek - ČVUT FEL wrote: > >> Optimizing foreach (array_keys($arr) as $k) is very important, not only >> because of memory, but because of speed when not all elements needs to >> be iterated, like: >> >> foreach (array_keys($arr) as $k) { >> >> if ($k some condition) { >> >> break; >> >> } >> >> } > > Can an iterator be the answer? E.g. > > foreach (new ArrayKeysIterator($arr) as $k) { ... } > > -- > > Best regards, > Max Semenik --=_d646f9189df85661bcc98d451ba5cfcb--