Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.330 diff -u -p -r1.330 bootstrap.inc --- includes/bootstrap.inc 22 Nov 2009 08:20:51 -0000 1.330 +++ includes/bootstrap.inc 28 Nov 2009 21:12:04 -0000 @@ -2156,16 +2156,33 @@ function registry_rebuild() { * function is called many times (100+) during a single page request, so * every microsecond of execution time that can be removed from the function * counts. These functions can use a more cumbersome, but faster variant of - * calling drupal_static(). For benchmarks and background on this variant, - * please see http://drupal.org/node/619666. + * calling drupal_static(). It works by storing the reference returned by + * drupal_static() in the calling function's own static variable, thereby + * removing the need to call drupal_static() for each iteration of the function. + * Conceptually, it replaces: + * @code + * $foo = &drupal_static(__FUNCTION__); + * @endcode + * with: + * @code + * // Unfortunately, this does not work. + * static $foo = &drupal_static(__FUNCTION__); + * @endcode + * However, the above line of code does not work, because PHP only allows static + * variables to be initializied by literal values, and does not allow static + * variables to be assigned to references. + * - http://php.net/manual/en/language.variables.scope.php#language.variables.scope.static + * - http://php.net/manual/en/language.variables.scope.php#language.variables.scope.references + * The example below shows the syntax needed to work around both limitations. + * For benchmarks and more information, @see http://drupal.org/node/619666. * * Example: * @code * function user_access($string, $account = NULL) { * // Use the advanced drupal_static() pattern, since this is called very often. - * static $drupal_static = array(); - * isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - * $perm = &$drupal_static[__FUNCTION__]; + * static $drupal_static; + * isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + * $perm = &$drupal_static[0]; * ... * } * @endcode Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1052 diff -u -p -r1.1052 common.inc --- includes/common.inc 26 Nov 2009 05:54:48 -0000 1.1052 +++ includes/common.inc 28 Nov 2009 21:12:04 -0000 @@ -2276,9 +2276,9 @@ function format_interval($timestamp, $gr */ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) { // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $timezones = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $timezones = &$drupal_static[0]; if (!isset($timezone)) { global $user; @@ -2517,9 +2517,9 @@ function url($path = NULL, array $option global $base_url, $base_secure_url, $base_insecure_url; // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $script = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $script = &$drupal_static[0]; if (!isset($script)) { // On some web servers, such as IIS, we can't omit "index.php". So, we @@ -4748,9 +4748,9 @@ function drupal_system_listing($mask, $d */ function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) { // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $functions = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $functions = &$drupal_static[0]; // Some alter hooks are invoked many times per page request, so statically // cache the list of functions to call, and on subsequent calls, iterate @@ -6237,9 +6237,9 @@ function drupal_check_incompatibility($v */ function entity_get_info($entity_type = NULL) { // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $entity_info = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $entity_info = &$drupal_static[0]; if (empty($entity_info)) { if ($cache = cache_get('entity_info')) { Index: includes/module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.175 diff -u -p -r1.175 module.inc --- includes/module.inc 26 Nov 2009 18:57:16 -0000 1.175 +++ includes/module.inc 28 Nov 2009 21:12:04 -0000 @@ -450,9 +450,9 @@ function module_hook($module, $hook) { */ function module_implements($hook, $sort = FALSE, $reset = FALSE) { // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $implementations = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $implementations = &$drupal_static[0]; // We maintain a persistent cache of hook implementations in addition to the // static cache to avoid looping through every module and every hook on each Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.48 diff -u -p -r1.48 path.inc --- includes/path.inc 20 Nov 2009 06:12:45 -0000 1.48 +++ includes/path.inc 28 Nov 2009 21:12:04 -0000 @@ -46,9 +46,9 @@ function drupal_path_initialize() { function drupal_lookup_path($action, $path = '', $path_language = '') { global $language; // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $cache = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $cache = &$drupal_static[0]; if (!isset($cache)) { $cache = array( @@ -257,9 +257,9 @@ function arg($index = NULL, $path = NULL // information), it should be resettable anyway in case a module needs to // free up the memory used by it. // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $arguments = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $arguments = &$drupal_static[0]; if (!isset($path)) { $path = $_GET['q']; @@ -325,9 +325,9 @@ function drupal_set_title($title = NULL, */ function drupal_is_front_page() { // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $is_front_page = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $is_front_page = &$drupal_static[0]; if (!isset($is_front_page)) { // As drupal_path_initialize updates $_GET['q'] with the 'site_frontpage' path, Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1084 diff -u -p -r1.1084 user.module --- modules/user/user.module 22 Nov 2009 04:22:54 -0000 1.1084 +++ modules/user/user.module 28 Nov 2009 21:12:05 -0000 @@ -692,9 +692,9 @@ function user_access($string, $account = // To reduce the number of SQL queries, we cache the user's permissions // in a static variable. // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static = array(); - isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__)); - $perm = &$drupal_static[__FUNCTION__]; + static $drupal_static; + isset($drupal_static) || ($drupal_static[0] = &drupal_static(__FUNCTION__)); + $perm = &$drupal_static[0]; if (!isset($perm[$account->uid])) { $role_permissions = user_role_permissions($account->roles);