Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.110
diff -u -b -r1.110 install.inc
--- includes/install.inc	24 Aug 2009 03:13:44 -0000	1.110
+++ includes/install.inc	9 Sep 2009 15:23:42 -0000
@@ -92,24 +92,30 @@
  *   Otherwise, FALSE.
  */
 function drupal_get_schema_versions($module) {
+  $updates = &drupal_static(__FUNCTION__, NULL);
+  if (!isset($updates) || !isset($updates[$module])) {
   $updates = array();
+    // Prepare regular expression to match all possible defined hook_update_N().
   $functions = get_defined_functions();
-  foreach ($functions['user'] as $function) {
-    if (strpos($function, $module . '_update_') === 0) {
-      $version = substr($function, strlen($module . '_update_'));
-      if (is_numeric($version)) {
-        $updates[] = $version;
+    // Narrow this down to functions ending with an integer, since all
+    // hook_update_N() functions end this way, and there are other
+    // possible functions which match '_update_'. We use preg_grep() here
+    // instead of foreaching through all defined functions, since the loop
+    // through all PHP functions can take significant page execution time
+    // and this function is called on every administrative page via
+    // system_requirements().
+    foreach (preg_grep('/_update_\d+$/', $functions['user']) as $function) {
+      // If this function is a module update function, add it to the list of
+      // module updates.
+      list($module_name, $number) = explode('_update_', $function);
+      $updates[$module_name][] = $number;
+    }
+    // Ensure that updates are applied in numerical order.
+    foreach ($updates as &$module_updates) {
+      sort($module_updates, SORT_NUMERIC);
       }
     }
-  }
-  if (count($updates) == 0) {
-    return FALSE;
-  }
-
-  // Make sure updates are run in numeric order, not in definition order.
-  sort($updates, SORT_NUMERIC);
-
-  return $updates;
+  return isset($updates[$module]) ? $updates[$module] : FALSE;
 }
 
 /**
