Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106113 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9065 invoked from network); 29 Jun 2019 20:47:20 -0000 Received: from unknown (HELO mail-oi1-f181.google.com) (209.85.167.181) by pb1.pair.com with SMTP; 29 Jun 2019 20:47:20 -0000 Received: by mail-oi1-f181.google.com with SMTP id s184so6725225oie.9 for ; Sat, 29 Jun 2019 11:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z4FIDmy5a1lsjwQvRRTUTTBA0x5pcUJKU1VwkBFhcVw=; b=lv53sY8aOXd5Idx/EI+G88ctUxvdEnvQIJWGcu4DaZUkddJ/lqBnZIMTYLlOqUBBkk vufvZi141QM/Dgc7jLpw9QWqA/muRFQ0mdMNtsrUzg1jsgDPstuQ3JUNvQMHu4473a// RdFsyQbNxuVkiGZzslP0WC7MU9QCvkath5VV7+EtXKbI6Qrs6swVvlfimXe/kPQpAJfG Z+ISCNor7r1FnNI3gNpgUBaQNfRwcF2gKJXfbKFtM+LSKFu0wNophZ+XMB8kKUzxFcNW a1a579YGFYj71SBZW97lWzzdUnSKt7V/fmzVDomfISSyI+v6tShYRDJhug9IQtYNtFUK RAlQ== 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=Z4FIDmy5a1lsjwQvRRTUTTBA0x5pcUJKU1VwkBFhcVw=; b=k29SeBgYgkvmmT/l2Fxn6C5fxHJ5vNoIcV2wzBzFq5Z2Zk2kPOaK1yIuCeuHZ646AC 6HCbConaKFhJhZ5xFHrga2qtNJ3wa8CJ72pRit0IyOhLBeCIchqdF+BCm6C1S8m4YJLK u8oxFhA31k85qrSz+TmjnNgi2+dBSGSNjLqZ4VCOZiKM8kI+MMS4E0AlIe0qTgTFnGsa UjAOj2tC2vTYY6yVlZGAIBYpZb2LRez2p2VAHtCpCQnFKzBTG3wqU1zEd7+bHlvxNFI9 wPVLX3Bi3kQpUEkup+lc6hHUgY9jcn361VpJ+lIBWcLnRELVNGTJBYElieThoPLAaoWu ELng== X-Gm-Message-State: APjAAAV8Iuyg/ubmpSizG+17mCmSYOABSRmc55SE2otCwxlvM5dxGppt HAGqNBT/hcZ659OtaKZ6SmUVVyzMfWnbzSQiEUc= X-Google-Smtp-Source: APXvYqyxolmN2CykUoXlwj5zhfIocB/j2wFSgmhB906TUbMazJi12lOVTjNh6pRUkChEKo168iKYyaJQZtjJs26cwNk= X-Received: by 2002:aca:5e06:: with SMTP id s6mr2081997oib.171.1561831472304; Sat, 29 Jun 2019 11:04:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 29 Jun 2019 20:04:18 +0200 Message-ID: To: Rowan Collins Cc: PHP Internals Content-Type: multipart/alternative; boundary="0000000000001b16d6058c7a3a42" Subject: Re: [PHP-DEV][RFC] Normalize array's "auto-increment" value on copy on write From: arnold.adaniels.nl@gmail.com (Arnold Daniels) --0000000000001b16d6058c7a3a42 Content-Type: text/plain; charset="UTF-8" On Thu, 20 Jun 2019, 19:06 Rowan Collins, wrote: > On Thu, 20 Jun 2019 at 13:11, Wes wrote: > > > I left that out of scope for the RFC, for reasons I don't have the > > knowledge to describe properly. In the following example, `unset()` > should > > reset the auto increment to `1` only after the third `unset()` call > > > > ``` > > $array = [0, 1, 2, 3]; // auto increment is 4 because there are "holes" > in > > the index > > unset($array[1]); // auto increment is still 4 > > unset($array[2]); // auto increment is still 4 > > unset($array[3]); // auto increment is 1, because the index sequence is > > contiguous, without holes > > ``` > > > > > I wonder if it would be possible (and sufficient) to detect if the element > being removed was the highest key, and only then look for the new "next" > value. > > The new value can be found either by decrementing the known value until you > hit an existing entry (optimal for large arrays with few gaps in the > sequence of keys) or by checking all the keys and finding the max (optimal > for small but sparse arrays like [12, 145, 65546]). > > # pseudocode: > > if ( key_being_unset == array.next_key - 1 ) { > if ( short_or_likely_to_be_sparse(array) ) { > new_highest_key = max(array.keys); > } else { > # Find highest unused number, starting from the one just deleted > do { > new_highest_key = key_being_unset - 1; > } while ( not key_exists(array, new_highest_key) ); > array.next_key = new_highest_key + 1; > } > } > > > I've no idea if this is plausible or not. > > Regards, > -- > Rowan Collins > [IMSoP] > As you state; this change is not BC. I'm not sure if I agree that this should be considered a simple bugfix. Maybe it would be good to add a secondary vote to decide if this should be implemented in PHP 7.4 or PHP 8. Arnold > --0000000000001b16d6058c7a3a42--