Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1031
diff -u -p -r1.1031 common.inc
--- includes/common.inc	27 Oct 2009 19:29:12 -0000	1.1031
+++ includes/common.inc	31 Oct 2009 06:00:18 -0000
@@ -2370,6 +2370,8 @@ function _format_date_callback(array $ma
  * alternative than url().
  */
 function url($path = NULL, array $options = array()) {
+  static $url_outbound;
+
   // Merge in defaults.
   $options += array(
     'fragment' => '',
@@ -2392,7 +2394,14 @@ function url($path = NULL, array $option
   $original_path = $path;
 
   // Allow other modules to alter the outbound URL and options.
-  drupal_alter('url_outbound', $path, $options, $original_path);
+  // Since PHP code cannot be unloaded, we statically cache the implementations
+  // of hook_url_outbound_alter() and only try to invoke them in case there any.
+  if (!isset($url_outbound)) {
+    $url_outbound = (bool) module_implements('url_outbound_alter');
+  }
+  if ($url_outbound) {
+    drupal_alter('url_outbound', $path, $options, $original_path);
+  }
 
   if ($options['fragment']) {
     $options['fragment'] = '#' . $options['fragment'];
