summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-07-18 01:22:53 +0000
committerDries Buytaert <dries@buytaert.net>2010-07-18 01:22:53 +0000
commitd828e2170b4923e29f5c531699bcd34b76f6da05 (patch)
treef744ca1cf3a581ac20faac20bb7f34fd8264e015 /includes
parent6195d47d15da7ca259b67c95d7d74f9fa2188e4c (diff)
downloadbrdo-d828e2170b4923e29f5c531699bcd34b76f6da05.tar.gz
brdo-d828e2170b4923e29f5c531699bcd34b76f6da05.tar.bz2
- Patch #768090 by ridgerunner: changed drupal_static() performance improvement.
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc41
1 files changed, 21 insertions, 20 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 327714cf9..47d369e2f 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -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;
}
/**