Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
object2array() uses a foreach loop to convert object attributes to array elements. This can be done about 2.4 times faster using a simple cast (array) operator. As an additional benefit, the type check for the argument being an object can be dropped, since casting an array to an array does no harm.
Patch forthcoming.
Comment | File | Size | Author |
---|---|---|---|
#10 | _41169_optimizearrayobject.patch | 9.33 KB | Chris Johnson |
#4 | arrayobjectoptimize4.6.patch | 1006 bytes | Chris Johnson |
#3 | arrayobjectoptimizeHead.patch | 989 bytes | Chris Johnson |
#1 | object2array_head.patch | 691 bytes | Chris Johnson |
Comments
Comment #1
Chris Johnson CreditAttribution: Chris Johnson commentedHere is a patch against HEAD, as of December 14, 2005.
Comment #2
Chris Johnson CreditAttribution: Chris Johnson commentedAh, just discovered that array2object() was likewise slow. I have patched my 4.7 test system for both routines to just use cast operators (array) and (object) and tested without errors.
Will be rolling new patch combining fixes for both routines, for HEAD/4.7 and 4.6.
Comment #3
Chris Johnson CreditAttribution: Chris Johnson commentedCombined patch against Head, December 14, 2005.
Comment #4
Chris Johnson CreditAttribution: Chris Johnson commentedCombined patch against 4.6 branch (4.6.5, December 12, 2005).
Comment #5
kquinn CreditAttribution: kquinn commentedWouldn't it be preferable to simply remove the object2array function and change all code that calls it to simply cast instead? If the overhead of the function call is at all significant (which I believe to be the case) that seems like it would be a significant improvement.
Thanks.
Comment #6
kquinn CreditAttribution: kquinn commentedRegarding my last comment: ditto array2object.
Comment #7
Dries CreditAttribution: Dries commentedGreat catch, Chris!
Comment #8
Chris Johnson CreditAttribution: Chris Johnson commentedOk, I will roll a patch for 4.7 only which removes the function calls and changes them all to casts.
Comment #9
Dries CreditAttribution: Dries commentedThanks!
Comment #10
Chris Johnson CreditAttribution: Chris Johnson commentedPatch for core HEAD (as of 0523GMT on 29 December).
This will break all contrib which uses either function, since they have now been deleted.
Comment #11
Dries CreditAttribution: Dries commentedCommitted. Wil you add a note to the upgrade guide?
Comment #12
Chris Johnson CreditAttribution: Chris Johnson commentedComment to module developer upgrade handbook posted.
Comment #13
(not verified) CreditAttribution: commented