Index: includes/path.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/path.inc,v
retrieving revision 1.16
diff -u -F^f -r1.16 path.inc
--- includes/path.inc	18 Jun 2007 06:59:11 -0000	1.16
+++ includes/path.inc	28 Jun 2007 19:09:40 -0000
@@ -1,6 +1,10 @@
 <?php
 // $Id: path.inc,v 1.16 2007/06/18 06:59:11 goba Exp $
 
+define(PATH_OPTIMIZATION_BLACKLIST, 0);
+define(PATH_OPTIMIZATION_WHITELIST, 1);
+define(PATH_OPTIMIZATION_NONE, 2);
+
 /**
  * @file
  * Functions to handle paths in Drupal, including path aliasing.
@@ -45,12 +49,12 @@ function drupal_init_path() {
  */
 function drupal_lookup_path($action, $path = '', $path_language = '') {
   global $language;
-  // $map is an array with language keys, holding arrays of Drupal paths to alias relations
+  // $map is an array with language keys, holding arrays of Drupal paths to alias relations.
   static $map = array(), $no_src = array(), $count;
 
   $path_language = $path_language ? $path_language : $language->language;
 
-  // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
+  // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases.
   if (!isset($count)) {
     $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
   }
@@ -60,19 +64,38 @@ function drupal_lookup_path($action, $pa
     $no_src = array();
   }
   elseif ($count > 0 && $path != '') {
+    static $optimization_type, $list;
+    
+    // Check if we should use the blacklist, the whitelist, or no optimization.
+    if (!isset($optimization_type)) {
+      $optimization_type = variable_get('path_optimization_type', PATH_OPTIMIZATION_NONE);
+      // We do not need to specify a default here, as you need to change
+      // the default optimize_type on the settings screen and then the
+      // variable will be saved anyways.
+      $list = variable_get('path_optimization_list', '');
+    }
+    
     if ($action == 'alias') {
       if (isset($map[$path_language][$path])) {
         return $map[$path_language][$path];
       }
-      // Get the most fitting result falling back with alias without language
-      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language));
+      // Get the most fitting result falling back with alias without language.
+      $query = "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC";
+      // In any of these cases, the path will be looked up, otherwise the
+      // alias will be set to FALSE:
+      //  - optimization_type is PATH_OPTIMIZATION_NONE
+      //  - optimization_type is PATH_OPTIMIZATION_BLACKLIST and the path
+      //    that is being looked up did not match a path in the blacklist
+      //  - optimization_type is PATH_OPTIMIZATION_WHITELIST and the path
+      //    that is being looked up did match a path in the whitelist
+      $alias = ($optimization_type == PATH_OPTIMIZATION_NONE || drupal_path_match($path, $list) == $optimization_type) ? db_result(db_query($query, $path, $path_language)) : FALSE;
       $map[$path_language][$path] = $alias;
       return $alias;
     }
     // Check $no_src for this $path in case we've already determined that there
-    // isn't a path that has this alias
+    // isn't a path that has this alias.
     elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
-      // Look for the value $path within the cached $map
+      // Look for the value $path within the cached $map.
       $src = '';
       if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
         // Get the most fitting result falling back with alias without language
@@ -220,3 +243,23 @@ function drupal_is_front_page() {
   // we can check it against the 'site_frontpage' variable.
   return $_GET['q'] == drupal_get_normal_path(variable_get('site_frontpage', 'node'));
 }
+
+/**
+ * Check if a path matches a set of patterns.
+ *
+ * @param $path
+ *   The path to match.
+ * @param $patterns
+ *   String containing a set of patterns separated by \n, \r or \r\n.
+ *
+ * @return
+ *   Boolean value: TRUE if the path matches a pattern, FALSE if otherwise.
+ */
+function drupal_path_match($path, $patterns) {
+  static $regexps;
+  
+  if (!isset($regexps[$patterns])) {
+    $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($patterns, '/')) .')$/';
+  }
+  return preg_match($regexps[$patterns], $path);
+}
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.267
diff -u -F^f -r1.267 block.module
--- modules/block/block.module	28 Jun 2007 00:39:47 -0000	1.267
+++ modules/block/block.module	28 Jun 2007 19:09:42 -0000
@@ -705,11 +705,10 @@ function block_list($region) {
       if ($block->pages) {
         if ($block->visibility < 2) {
           $path = drupal_get_path_alias($_GET['q']);
-          $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
           // Compare with the internal and path alias (if any).
-          $page_match = preg_match($regexp, $path);
+          $page_match = drupal_path_match($path, $block->pages);
           if ($path != $_GET['q']) {
-            $page_match = $page_match || preg_match($regexp, $_GET['q']);
+            $page_match = $page_match || drupal_path_match($_GET['q'], $block->pages);
           }
           // When $block->visibility has a value of 0, the block is displayed on
           // all pages except those listed in $block->pages. When set to 1, it
