Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115585 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16662 invoked from network); 26 Jul 2021 13:14:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jul 2021 13:14:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 29D681804B0 for ; Mon, 26 Jul 2021 06:41:24 -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=2.7 required=5.0 tests=BAYES_05, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.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 ; Mon, 26 Jul 2021 06:41:23 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id x7so11303865ljn.10 for ; Mon, 26 Jul 2021 06:41:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RjnVDyN+8XKuuargOGqjZZ9zFsmZCMVLTkICnb2fDKM=; b=SGbuG8gjFRDBDU6jbwC7wls4cvlzfBL9WsCtSm/O3ntQdHyL5y3NoaIf08QQf9kR0L ul+gaOExEPJveQqUGLpMTizVUPEAJUP0zCQ9hsyFgVUxRAQrN+aBSc5NmWvmu0u4M/nd W2gCCd7JsBcOXqRTseDq+zNLHwuPq4plV9QaY29D11oNPFdfYDoLjGHEru+aHH7S9Y90 lltGN4EJE4YXJjU3fd+MGHk33Gba01/Afz7lYA1vcroR5mu9iFryfEgPrkfQeuNBTcto P5oULQ/oaYk+sJqeT3CzSaC0z+D96v5Uiw+9Q4ucAmEpDfY4dEOao64JezkUCx4V7V3L WSIQ== X-Gm-Message-State: AOAM533mn1pj+GkAURr6pTIdlQyTmcjtRoJQ82z2kETl8hN0Hc5hjtn1 dYM3xiOsBCUxR5CKN3fpBq4lqi5zucuXKQBDUZjZ9m1as/0N1cTk X-Google-Smtp-Source: ABdhPJz02r93A9wAz3pIcSxeeDxNMLWXn+CDrsXuWNkF/RBnNQ1i+LTouyN+od0DkD1JAGMoAlIUfKnRNFO5x5eNHTI= X-Received: by 2002:a05:651c:626:: with SMTP id k38mr11773889lje.304.1627306881932; Mon, 26 Jul 2021 06:41:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 26 Jul 2021 08:41:11 -0500 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000a3758005c806e8d6" Subject: Re: [PHP-DEV] array_merge() inside looping optimization From: pollita@php.net (Sara Golemon) --000000000000a3758005c806e8d6 Content-Type: text/plain; charset="UTF-8" On Sun, Jul 25, 2021 at 4:35 PM David Rodrigues wrote: > Anyway, I don't know if this is actually possible, or if the cost-benefit > would be better than what there is today. But I believe it is a path to be > thought of. > Sadly, no. The function doesn't know where the variable is going to be stored to, so it can't know if the one reference it's receiving is about to be overwritten. Technically, the information is in the op_array, but exposing that to an implementation handler is... dangerous and sets a bad precedent. A much more direct and maintainable solution would be to introduce a new function that intentionally modifies by reference. This doesn't give us a free fix for existing code, but it does provide a path for new code to be more efficient. So then you have to ask, should we kitchen sink something in for this? Maybe, the perf argument is compelling. I'd also argue that this request reinforces calls for type methods. $arr->push($otherArr); would be a stronger candidate, for example. In fact, I think the DS extension might actually have what you're looking for already. TL;DR - Maybe look at https://www.php.net/manual/en/ds-map.putall.php ? -Sara --000000000000a3758005c806e8d6--