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.
follow-up to: #254491: Standardize static caching
see last patch examples: http://drupal.org/node/254491#comment-1430180 and also: http://drupal.org/node/224333#static_variable_api
Apply this conversion pattern to includes/locale.inc to convert all static variables there. Pay close attention to any place a reset parameter is provided and add a call to drupal_static_reset() where appropriate (e.g. in any calling function that uses the reset parameter)
Comment | File | Size | Author |
---|---|---|---|
#12 | jamesan_422364-12.patch | 2.64 KB | JamesAn |
#9 | jamesan_422364-9.patch | 1.36 KB | JamesAn |
#6 | jamesan_422364-3.patch | 1.36 KB | JamesAn |
#3 | jamesan_422364-2.patch | 1.36 KB | JamesAn |
#1 | jamesan_422364.patch | 1.33 KB | JamesAn |
Comments
Comment #1
JamesAn CreditAttribution: JamesAn commentedLet's give this static catching change a shot!
Comment #3
JamesAn CreditAttribution: JamesAn commentedBah. I misunderstood; I was wondering why the first parameter was always __FUNCTION__ and then realized, that was just to ensure the parameter was unique. So functions with multiple static vars need to rename subsequent strings sent into drupal_static. I gets it now!
Comment #4
JamesAn CreditAttribution: JamesAn commentedGah. Forgot to flip the switch.
Comment #5
pwolanin CreditAttribution: pwolanin commentedPer discussion w/ catch - if you have a variable name more complex than just __FUNCTION__, use a ':' to separate the suffix (this will avoid colliding with any other valid function name). e.g. :
Comment #6
JamesAn CreditAttribution: JamesAn commentedGotcha. Here's attempt #3!
Comment #7
Dries CreditAttribution: Dries commentedThe default value of drupal_static() is NULL so you don't need to pass that in explicitly. See the last chunk of your patch.
Comment #8
pwolanin CreditAttribution: pwolanin commentedPer IRC discussion, in this case I might write something like this, since the logic suggests there is some decoupling between header and string processing, but we want to reset strings and report at the same time.
Comment #9
JamesAn CreditAttribution: JamesAn commented@Dries: Thanks for pointing that out. It's fixed.
@pwolanin: I don't know. The logic and purpose of
$strings
and$report
seem pretty distinct to me. I don't think it'd be good to group them together like that as it creates an exceptional case wheredrupal_static_reset()
will reset two variables, but not the third.There should be a way to either reset specific vars (as it is now) or bulk-reset all vars of a function. Resetting some and not others seems a bit too ad-hoc, in my opinion. yes/no?
Comment #10
Dries CreditAttribution: Dries commentedWhile we are at it, we might want to rename 'headerdone' -- we don't usually glue variable names together.
Comment #11
pwolanin CreditAttribution: pwolanin commented@JamesAn - either way is ok for me - this function doesn't have any reset functionality currently, so no real expectation to meet.
Comment #12
JamesAn CreditAttribution: JamesAn commentedheaderdone changed to header_done.
@pwolanin, yea, reset doesn't happen there.
Comment #13
pwolanin CreditAttribution: pwolanin commentedLooks good
Comment #14
pwolanin CreditAttribution: pwolanin commentedSince all tests pass and code style looks fine, I think it's good enough.
Comment #15
Dries CreditAttribution: Dries commentedThis looks like proper use of the static caching API. Committed to CVS HEAD. Thanks.