Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.148
diff -u -p -r1.148 module.inc
--- includes/module.inc	23 Jul 2009 21:14:09 -0000	1.148
+++ includes/module.inc	27 Jul 2009 20:16:04 -0000
@@ -346,9 +346,15 @@ function module_hook($module, $hook) {
  *   the implementations are loaded as necessary.
  */
 function module_implements($hook, $sort = FALSE) {
-  static $implementations = array(), $sorted_implementations = array(), $loaded = array(), $cached_hooks = 0;
+  static $implementations = array(), $sorted_implementations = array(), $loaded = array(), $cached_hooks = 0, $maintenance;
 
-  if (defined('MAINTENANCE_MODE')) {
+  // Use a static variable for maintenance mode to avoid the overhead of
+  // calling defined() each time the function is called.
+  if (!isset($maintenance)) {
+    $maintenance = defined('MAINTENANCE_MODE');
+  }
+
+  if ($maintenance) {
     return _module_implements_maintenance($hook, $sort);
   }
   if ($hook === MODULE_IMPLEMENTS_CLEAR_CACHE) {
