Problem/Motivation

Follow-up from comment by @alexpott #3172166-34: Element::properties() produces notices if given an array with integer keys.

The Element::child() must be the inverse of Element::property() - so let's make this true in code. Element::children() should also follow the same logic.

Proposed resolution

For Element::child()

   public static function child($key) {
-    return !isset($key[0]) || $key[0] != '#';
+    return !static::property($key);
   }

For "Element::children() we have if (is_int($key) || $key === '' || $key[0] !== '#') { I guess we're inlining this here for performance - which makes sense (up to a point - this stuff is called thousands of times so often the measuring makes it seem way way slower than it actually is). But regardless - we can still make this more efficient by doing if (!(is_string($key) && $key[0] !== '#')). "

"Note the performance arguments for Element::child() don't really hold based on core usage."

Remaining tasks

Make changes.
Does this also require checking for performance for Element::children()?

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

CommentFileSizeAuthor
#3 3262736-3.patch893 bytesandregp

Comments

ekes created an issue. See original summary.

ekes’s picture

Issue summary: View changes
andregp’s picture

Status: Active » Needs review
StatusFileSize
new893 bytes

Hi @ekes, what else should I do?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Seems there were failures in last patch.

Even though this is a task will it require a test?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.