From ec1f481eb395f02c57e86ae80d4f839c94c846bd Mon Sep 17 00:00:00 2001 From: mark burdett Date: Mon, 7 Mar 2011 08:58:42 +0000 Subject: [PATCH] Issue #1081266 by mfb: Avoid re-scanning module directory when multiple modules are missing. --- includes/bootstrap.inc | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-) diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index fe1741d..069b6c6 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -656,7 +656,7 @@ function drupal_settings_initialize() { function drupal_get_filename($type, $name, $filename = NULL) { // The location of files will not change during the request, so do not use // drupal_static(). - static $files = array(); + static $files = array(), $dirs = array(); if (!isset($files[$type])) { $files[$type] = array(); @@ -702,16 +702,19 @@ function drupal_get_filename($type, $name, $filename = NULL) { $extension = $type; } - if (!function_exists('drupal_system_listing')) { - require_once DRUPAL_ROOT . '/includes/common.inc'; - } - // Scan the appropriate directories for all files with the requested - // extension, not just the file we are currently looking for. This - // prevents unnecessary scans from being repeated when this function is - // called more than once in the same page request. - $matches = drupal_system_listing("/^" . DRUPAL_PHP_FUNCTION_PATTERN . "\.$extension$/", $dir, 'name', 0); - foreach ($matches as $matched_name => $file) { - $files[$type][$matched_name] = $file->uri; + if (!isset($dirs[$dir][$extension])) { + $dirs[$dir][$extension] = TRUE; + if (!function_exists('drupal_system_listing')) { + require_once DRUPAL_ROOT . '/includes/common.inc'; + } + // Scan the appropriate directories for all files with the requested + // extension, not just the file we are currently looking for. This + // prevents unnecessary scans from being repeated when this function is + // called more than once in the same page request. + $matches = drupal_system_listing("/^" . DRUPAL_PHP_FUNCTION_PATTERN . "\.$extension$/", $dir, 'name', 0); + foreach ($matches as $matched_name => $file) { + $files[$type][$matched_name] = $file->uri; + } } } } -- 1.7.4.1