Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
d828e217
Commit
d828e217
authored
Jul 18, 2010
by
Dries
Browse files
- Patch
#768090
by ridgerunner: changed drupal_static() performance improvement.
parent
6195d47d
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/bootstrap.inc
View file @
d828e217
...
...
@@ -2906,34 +2906,35 @@ function registry_update() {
*/
function
&
drupal_static
(
$name
,
$default_value
=
NULL
,
$reset
=
FALSE
)
{
static
$data
=
array
(),
$default
=
array
();
if
(
!
isset
(
$name
))
{
// All variables are reset. This needs to be done one at a time so that
// references returned by earlier invocations of drupal_static() also get
// reset.
foreach
(
$default
as
$name
=>
$value
)
{
$data
[
$name
]
=
$value
;
}
// As the function returns a reference, the return should always be a
// variable.
return
$data
;
}
if
(
$reset
)
{
// The reset means the default is loaded.
if
(
array_key_exists
(
$name
,
$default
))
{
// First check if dealing with a previously defined static variable.
if
(
isset
(
$data
[
$name
])
||
array_key_exists
(
$name
,
$data
))
{
// Non-NULL $name and both $data[$name] and $default[$name] statics exist.
if
(
$reset
)
{
// Reset pre-existing static variable to its default value.
$data
[
$name
]
=
$default
[
$name
];
}
else
{
return
$data
[
$name
];
}
// Neither $data[$name] nor $default[$name] static variables exist.
if
(
isset
(
$name
))
{
if
(
$reset
)
{
// Reset was called before a default is set and yet a variable must be
// returned.
return
$data
;
}
}
elseif
(
!
array_key_exists
(
$name
,
$data
))
{
// Store the default value internally and also copy it to the reference to
// be returned.
// First call with new non-NULL $name. Initialize a new static variable.
$default
[
$name
]
=
$data
[
$name
]
=
$default_value
;
return
$data
[
$name
];
}
// Reset all: ($name == NULL). This needs to be done one at a time so that
// references returned by earlier invocations of drupal_static() also get
// reset.
foreach
(
$default
as
$name
=>
$value
)
{
$data
[
$name
]
=
$value
;
}
return
$data
[
$name
];
// As the function returns a reference, the return should always be a
// variable.
return
$data
;
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment