diff --git a/includes/rules.core.inc b/includes/rules.core.inc
index 24d85c6..cdb2636 100644
--- a/includes/rules.core.inc
+++ b/includes/rules.core.inc
@@ -1804,16 +1804,22 @@ abstract class RulesAbstractPlugin extends RulesPlugin {
   }
 
   protected function getFileName($function, $includes) {
-    $reflector = new ReflectionFunction($function);
-    // On windows the path contains backslashes instead of slashes, fix that.
-    $file = str_replace('\\', '/', $reflector->getFileName());
-    foreach ($includes as $include) {
-      $pos = strpos($file, $include . '.inc');
-      // Test whether the file ends with the given filename.inc.
-      if ($pos !== FALSE && strlen($file) - $pos == strlen($include) + 4) {
-        return $include;
+    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());
+      foreach ($includes as $include) {
+        $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];
   }
 }
 
diff --git a/rules.rules.inc b/rules.rules.inc
index fcd3c94..8c82002 100644
--- a/rules.rules.inc
+++ b/rules.rules.inc
@@ -21,13 +21,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');
-  foreach (array('comment', 'taxonomy', 'php', 'path') as $module) {
-    if (module_exists($module)) {
-      $return[] = $module;
+  // 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)) {
+        $modules[] = $module;
+      }
     }
   }
-  return $return;
+  return $modules;
 }
 
 /**
@@ -47,12 +56,20 @@ function _rules_rules_collect_items($hook) {
  * Implements hook_rules_file_info().
  */
 function rules_rules_file_info() {
-  $items = array();
-  foreach (rules_core_modules() as $module) {
-    if (function_exists($function = "rules_{$module}_file_info")) {
-      $items = array_merge($items, (array)$function());
-      // Automatically add "$module.rules.inc" for each module.
-      $items[] = 'modules/' . $module . '.rules';
+  // 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")) {
+        $items = array_merge($items, (array) $function());
+        // Automatically add "$module.rules.inc" for each module.
+        $items[] = 'modules/' . $module . '.rules';
+      }
     }
   }
   return $items;
