Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.96
diff -u -p -r1.96 install.inc
--- includes/install.inc	15 Jul 2009 02:08:41 -0000	1.96
+++ includes/install.inc	18 Jul 2009 03:15:03 -0000
@@ -92,24 +92,28 @@ function drupal_load_updates() {
  *   Otherwise, FALSE.
  */
 function drupal_get_schema_versions($module) {
-  $updates = array();
-  $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;
-      }
+  $updates = &drupal_static(__FUNCTION__, NULL);
+  if (!isset($updates)) {
+    $updates = array();
+    // Prepare regular expression to match all possible module update functions.
+    $regexp = '/^(' . implode('|', module_list()) . ')_update_(\d+)$/';
+    $functions = get_defined_functions();
+    // Filter all defined user functions by functions ending in numbers first
+    // (as module update functions do).
+    foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
+      // If this function is a module update function, add it to the list of
+      // module updates.
+      if (preg_match($regexp, $function, $matches)) {
+        list(, $module, $number) = $matches;
+        $updates[$module][] = $number;
+      }
+    }
+    // Ensure that module updates are applied in a 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;
 }
 
 /**
