Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
9 Aug 2020 at 03:13 UTC
Updated:
21 Feb 2022 at 11:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jungleThe scope of #3044373: Improve performance by not using array_merge() in a loop in TestSetupTrait::getConfigSchemaExclusions() is too narrow, and the patch there is not ready yet to me, so instead of rescoping it, filed a new one with a large scope covering the whole codebase.
Maybe we could/should turn this one into a meta.
Comment #3
jungleThe first iteration.
Comment #4
jungleIt's not easy to find and identify all refactorable usages, so changing the title a little bit.
Comment #5
dwwThanks for proposing this and getting the patch started!
Interesting. A new language feature. Slick! ;)
However, the '...' array "spread" operator only exists in PHP 7.4. We'll have to wait for a version of core where that's the minimum. So far, 9.1.x still allows PHP 7.3. Might have to bump this to 10.0.x, TBD.
Meanwhile, some questions / concerns about how this should work once we can use it:
If I'm reading the spec correctly, I believe this could just be:
No?
Why bother? Why not still
return $dependenciesand just change what we're doing in the loop?Seems like a no-op. Don't you end up with $errors the same before an after this line? How/why are they different?
I don't think we nee this, but if we did, I believe it would be:
return [...$errors, ...$nested_errors];But again, I'd rather we just did:
$errors[] = %this->checkValue(...);and then keep
return $errors;These two lines should be enough for this whole hunk.
no-op?
There's lots more of the above in the rest of the patch, but I'll stop here and see what's up. ;)
Thanks!
-Derek
Comment #6
dwwActually, seems that a lot of this could be refactored now without
...$fooat all. E.g.:We definitely don't need to
array_merge()each time inside the loop, but we don't need...$to replace it, either.Comment #7
jungleThanks @dww.
It's not PHP 7.4 only or 7.4+ available, see the link I added in IS. The above are examples from that page. Queued a testing against PHP 7.3.
...here is variadic since PHP 5.6, not spread operator.We have variadics usages in core. #3125032: Use variadics in Cache::merge* functions - for example Cache::mergeTags()
Comment #8
jungleThe testing in #3 against PHP 7.3 passed, setting back to NR.
Comment #11
sylus commentedComment #12
akhildev.cs commentedhi
patch #11 applied successfully
drupal 9.3.x-dev & php 7.3
This seems removed all possible "array_merge" from inside the loop.
thankyou.
Comment #14
joachim commentedComment #15
alexpottThe code is certainly prettier in many cases. Nice work.
Committed and pushed cbcdb8b2d42 to 10.0.x and 3cf6d577f81 to 9.4.x. Thanks!
We should get a follow-up for Drupal 10. Since the minim version of PHP there is 8... we change
return array_merge([], ...$dependencies);TO
return array_merge(...$dependencies);Comment #18
alexpott@Akhildev.cs please don't post screenshots of code being applied. DrupalCI tells us this already so it looks like a comment purely make to receive issue credit.