Commit 2373c925 authored by Peter Philipp's avatar Peter Philipp Committed by Wolfgang Ziegler
Browse files

Issue #2200717 by das-peter: Add more static caching

parent b79bbb97
Loading
Loading
Loading
Loading
+6 −0
Changes for includes/rules.core.inc: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1805,6 +1805,9 @@ abstract class RulesAbstractPlugin extends RulesPlugin {
  }

  protected function getFileName($function, $includes) {
    static $filenames;
    if (!isset($filenames) || !array_key_exists($function, $filenames)) {
      $filenames[$function] = NULL;
      $reflector = new ReflectionFunction($function);
      // On windows the path contains backslashes instead of slashes, fix that.
      $file = str_replace('\\', '/', $reflector->getFileName());
@@ -1812,10 +1815,13 @@ abstract class RulesAbstractPlugin extends RulesPlugin {
        $pos = strpos($file, $include . '.inc');
        // Test whether the file ends with the given filename.inc.
        if ($pos !== FALSE && strlen($file) - $pos == strlen($include) + 4) {
          $filenames[$function] = $include;
          return $include;
        }
      }
    }
    return $filenames[$function];
  }
}

/**
+20 −3
Changes for rules.rules.inc: 20 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -20,13 +20,22 @@ foreach (rules_core_modules() as $module) {
 * for providing some general stuff.
 */
function rules_core_modules() {
  $return = array('data', 'entity', 'node', 'system', 'user', 'rules_core');
  // Make use of the fast, advanced drupal static pattern.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast = &drupal_static(__FUNCTION__);
  }
  $modules = &$drupal_static_fast;

  if (!isset($modules)) {
    $modules = array('data', 'entity', 'node', 'system', 'user', 'rules_core');
    foreach (array('comment', 'taxonomy', 'php', 'path') as $module) {
      if (module_exists($module)) {
      $return[] = $module;
        $modules[] = $module;
      }
    }
  }
  return $return;
  return $modules;
}

/**
@@ -46,6 +55,13 @@ function _rules_rules_collect_items($hook) {
 * Implements hook_rules_file_info().
 */
function rules_rules_file_info() {
  // Make use of the fast, advanced drupal static pattern.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast = &drupal_static(__FUNCTION__);
  }
  $items = &$drupal_static_fast;
  if (!isset($items)) {
    $items = array();
    foreach (rules_core_modules() as $module) {
      if (function_exists($function = "rules_{$module}_file_info")) {
@@ -54,6 +70,7 @@ function rules_rules_file_info() {
        $items[] = 'modules/' . $module . '.rules';
      }
    }
  }
  return $items;
}