Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Jul 2011 at 16:38 UTC
Updated:
27 Jan 2017 at 17:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tim.plunkettThis patch assumes #1216758: Add $module and $hook as formal parameters in module_invoke() is already committed.
Comment #2
tim.plunkettSince the indices are not important, these should be removed with
unset(), notarray_shift(). Thanks to chx for pointing out how much faster unset is.Comment #3
droplet commentedarray_shift is bad in performance
Comment #4
sunExcellent, thanks!
Comment #5
sund'oh, sorry.
Comment #7
tim.plunkettThis gets smaller and less exciting each time. But I learned plenty about when Drupal cares about indices, and cool things about call_user_func_array...
Comment #8
sunCan you enlighten us, too, please? :) Why did #2 fail?
Comment #9
droplet commented@sun,
the failed tests are hardcode the args key. eg.
array_shift reorder the index key from ZERO and unset just remove an element from array only.
Comment #10
sunComment #11
sun#7: drupal-1217840-7.patch queued for re-testing.
Comment #13
tim.plunkettI see no reason to babysit that code.
Comment #14
tim.plunkettThis is the last of it.
Comment #15
sunI'm OK with the changes in this patch that only effect subsequent code, which is doing stuff like implode().
In other words, I'd like to see the changes to form.inc reverted. (but fine with adding a comment as in #7)
Comment #16
tim.plunkettI'd agree for the D7 backport. But this is D8, there is no reason for an implementation of hook_form_alter() to blindly trust the array keys in $form_state['build_info']['args'], and we can document that and fix it.
Comment #17
sunThere's lots of code that's doing that outside of core, and that's why I disagree with it. It's a perfectly fine way for accessing the arguments, and I do not see why we want to break such code. Contrary to that, the change to unset() is a pure micro-optimization only.
Comment #18
tim.plunkettHere's another approach then.
sun, if you really disagree with this one too, can we chat about it in IRC sometime?
Comment #20
tim.plunkett#18: drupal-1217840-18.patch queued for re-testing.
Comment #21
tim.plunkettThe difference between #14 and #18 is that first index of
$form_state['build_info']['args']will be 2 or 0, respectively.I'd just as soon go with #18 since its not an API change.
Comment #22
sunI've to admit that there's no difference between unset() + array_values(), but at the same time, array_shift() is just one amount of confusion.
Also, did we check the behavior of PHP references with array_values()?
Comment #23
tim.plunkettRerolled. And yes, I tested array_values(), it doesn't affect PHP references
Comment #24
tim.plunkettRerolled.
Comment #25
tim.plunkettComment #26
andypostInteresting how this impacts on performance ;)
Comment #27
catchCommitted/pushed to 8.x, thanks!
Moving 7.x for backport.
Comment #28
dcam commentedBackported #25 to D7.
There were only a couple of things to backport. module_invoke_all() in D7 already uses unset() and the changes to Views aren't relevant.
Comment #29
yesct commentedwhy do we have to do array_values in the second case, and not in the first?
I went back and re-read some comments... maybe because
Does array_values reorder from zero then?
http://us2.php.net/manual/en/function.array-values.php
"array_values() returns all the values from the array and indexes the array numerically."
tim said in #16
and then added some array_values() in #18.
I would have thought we would have had to do unset and then array values all the time? ...
and why not do it right after the unset? like:
+ unset($args[0]);
+ // Put reason here...
+ $args=array_values($args);
$form_state['build_info']['args'] = $args;
OTOH, this is a backport... so maybe we should just do it the same as was done for drupal 8. (but I am curious)
Comment #30
mgiffordEDIT: Sorry, pasted in the wrong text.
Just looks like most of @YesCT's comments have to do with D8. Do we want to re-open this or just accept the decisions made in D8. If we want to accept them, we should be able to just back-port them to D7, right?