--- includes/bootstrap.inc.orig	2006-01-09 16:59:40.000000000 -0500
+++ includes/bootstrap.inc	2006-01-09 20:00:31.000000000 -0500
@@ -332,7 +332,7 @@
   // print $name. '<br />';
   static $files = array();
 
-  if ($files[$type][$name]) {
+  if (isset($files[$type][$name])) {
     return TRUE;
   }
 
@@ -349,32 +349,67 @@
 }
 
 /**
- * Return an array mapping path aliases to their internal Drupal paths.
- */
-function drupal_get_path_map($action = '') {
-  static $map = NULL;
-
-  if ($action == 'rebuild') {
-    $map = NULL;
-  }
-
-  if (is_null($map)) {
-    $map = array();  // Make $map non-null in case no aliases are defined.
-    $result = db_query('SELECT * FROM {url_alias}');
-    while ($data = db_fetch_object($result)) {
-      $map[$data->dst] = $data->src;
+ * Given an alias, return its Drupal system URL if one exists.  Given a Drupal
+ * system URL return its alias if one exists.
+ * @param $action
+ *  One of the following values:
+ *  - wipe: delete the alias cache.
+ *  - source: indicates that given a Drupal system URL, return an alias if one
+ *            exists.
+ *  - alias: indicates that given a path alias, return the Drupal system URL if
+ *           one exists.
+ * @param $path
+ *  The path to investigate for corresponding aliases or system URLs.
+ */
+function drupal_lookup_path($action, $path = '') {
+  static $map = array();
+  static $count = NULL;
+
+  if ($count === NULL) {
+    $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
+  }
+
+  if ($action == 'wipe') {
+    $map = array();
+  }
+  elseif ($count > 0 && $path != '') {
+    if ($action == 'alias') {
+      if (isset($map[$path])) {
+        return $map[$path];
+      }
+      if ($alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) {
+        $map[$path] = $alias;
+        return $alias;
+      }
+      else {
+        $map[$path] = $path;
+      }
+    }
+    elseif ($action == 'source') {
+      if ($alias = array_search($path, $map)) {
+        return $alias;
+      }
+      if (!isset($map[$path])) {
+        if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
+          $map[$src] = $path;
+          return $src;
+        }
+        else {
+          $map[$path] = $path;
+        }
+      }
     }
   }
 
-  return $map;
+  return FALSE;
 }
 
 /**
  * Given an internal Drupal path, return the alias set by the administrator.
  */
 function drupal_get_path_alias($path) {
-  if (($map = drupal_get_path_map()) && ($newpath = array_search($path, $map))) {
-    return $newpath;
+  if ($alias = drupal_lookup_path('alias', $path)) {
+    return $alias;
   }
   elseif (function_exists('conf_url_rewrite')) {
     return conf_url_rewrite($path, 'outgoing');
@@ -532,7 +567,7 @@
     $arguments = explode('/', $_GET['q']);
   }
 
-  if (array_key_exists($index, $arguments)) {
+  if ($arguments[$index] !== NULL) {
     return $arguments[$index];
   }
 }
--- includes/common.inc.orig	2006-01-09 17:09:40.000000000 -0500
+++ includes/common.inc	2006-01-09 19:57:05.000000000 -0500
@@ -65,18 +65,18 @@
 }
 
 /**
- * Regenerate the path map from the information in the database.
+ * Reset the static variable which holds the aliases mapped for this request.
  */
-function drupal_rebuild_path_map() {
-  drupal_get_path_map('rebuild');
+function drupal_clear_path_cache() {
+  drupal_lookup_path('wipe');
 }
 
 /**
  * Given a path alias, return the internal path it represents.
  */
 function drupal_get_normal_path($path) {
-  if (($map = drupal_get_path_map()) && isset($map[$path])) {
-    return $map[$path];
+  if ($src = drupal_lookup_path('source', $path)) {
+    return $src;
   }
   elseif (function_exists('conf_url_rewrite')) {
     return conf_url_rewrite($path, 'incoming');
@@ -1465,7 +1465,7 @@
  *   An HTML string ready for insertion in a tag.
  */
 function drupal_attributes($attributes = array()) {
-  if ($attributes) {
+  if (is_array($attributes)) {
     $t = array();
     foreach ($attributes as $key => $value) {
       $t[] = $key .'="'. check_plain($value) .'"';
@@ -1484,7 +1484,8 @@
  * @param $text
  *   The text to be enclosed with the anchor tag.
  * @param $path
- *   The Drupal path being linked to, such as "admin/node".
+ *   The Drupal path being linked to, such as "admin/node".  Note, this must be
+ *   a system URL as the url() function will generate the alias.
  * @param $attributes
  *   An associative array of HTML attributes to apply to the anchor tag.
  * @param $query
@@ -1500,7 +1501,7 @@
  *   an HTML string containing a link to the given path.
  */
 function l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
-  if (drupal_get_normal_path($path) == $_GET['q']) {
+  if ($path == $_GET['q']) {
     if (isset($attributes['class'])) {
       $attributes['class'] .= ' active';
     }
--- modules/path.module.orig	2006-01-09 17:15:19.000000000 -0500
+++ modules/path.module	2006-01-09 17:34:56.000000000 -0500
@@ -132,11 +132,11 @@
 function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
   if ($path && !$alias) {
     db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
-    drupal_rebuild_path_map();
+    drupal_clear_path_cache();
   }
   else if (!$path && $alias) {
     db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
-    drupal_rebuild_path_map();
+    drupal_clear_path_cache();
   }
   else if ($path && $alias) {
     $path_count = db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE src = '%s'", $path));
@@ -145,7 +145,7 @@
     // We have an insert:
     if ($path_count == 0 && $alias_count == 0) {
       db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
-      drupal_rebuild_path_map();
+      drupal_clear_path_cache();
     }
     else if ($path_count >= 1 && $alias_count == 0) {
       if ($pid) {
@@ -154,11 +154,11 @@
       else {
         db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
       }
-      drupal_rebuild_path_map();
+      drupal_clear_path_cache();
     }
     else if ($path_count == 0 && $alias_count == 1) {
       db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s'", $path, $alias);
-      drupal_rebuild_path_map();
+      drupal_clear_path_cache();
     }
     else if ($path_count == 1 && $alias_count == 1) {
       // This will delete the path that alias was originally pointing to:
--- database/database.mysql.orig	2006-01-09 20:56:32.000000000 -0500
+++ database/database.mysql	2006-01-09 20:55:43.000000000 -0500
@@ -476,7 +476,8 @@
   src varchar(128) NOT NULL default '',
   dst varchar(128) NOT NULL default '',
   PRIMARY KEY (pid),
-  UNIQUE KEY dst (dst)
+  UNIQUE KEY dst (dst),
+  KEY src (src)
 ) TYPE=MyISAM;
 
 --
--- database/database.pgsql.orig	2006-01-09 20:56:08.000000000 -0500
+++ database/database.pgsql	2006-01-09 20:58:00.000000000 -0500
@@ -488,6 +488,7 @@
   PRIMARY KEY  (pid)
 );
 CREATE INDEX url_alias_dst_idx ON url_alias(dst);
+CREATE INDEX url_alias_src_idx ON url_alias(src);
 --
 -- Table structure for permission
 --
--- database/updates.inc.orig	2006-01-09 21:00:34.000000000 -0500
+++ database/updates.inc	2006-01-09 21:03:26.000000000 -0500
@@ -107,7 +107,8 @@
   "2005-03-21" => "update_128",
   "2005-04-14" => "update_129",
   "2005-05-06" => "update_130",
-  "2005-05-07" => "update_131"
+  "2005-05-07" => "update_131",
+  "2005-01-09" => "update_132"
 );
 
 function update_32() {
@@ -2394,6 +2395,19 @@
   return $ret;
 }
 
+function update_132() {
+  $ret = array();
+
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)");
+  }
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("CREATE INDEX url_alias_src ON {url_alias}(src)");
+  }
+
+  return $ret;
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
