From 12b5c9c93e110d101adbcdb7238f400397ef5534 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 25 Jul 2011 20:18:07 +0000 Subject: [PATCH] Optimize parse_request for the home page. Props duck_. see #17177 git-svn-id: https://develop.svn.wordpress.org/trunk@18466 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/class-wp.php | 80 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index cf671bd79d..9e4b769b7c 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -185,54 +185,52 @@ class WP { // Look for matches. $request_match = $request; - foreach ( (array) $rewrite as $match => $query) { - // Don't try to match against AtomPub calls - if ( $req_uri == 'wp-app.php' ) - break; - - // If the requesting file is the anchor of the match, prepend it - // to the path info. - if ( (! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request) ) - $request_match = $req_uri . '/' . $request; - - if ( preg_match("#^$match#", $request_match, $matches) || - preg_match("#^$match#", urldecode($request_match), $matches) ) { - // Got a match. - $this->matched_rule = $match; - - // Trim the query of everything up to the '?'. - $query = preg_replace("!^.+\?!", '', $query); - - // Substitute the substring matches into the query. - $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); - - $this->matched_query = $query; - - // Parse the query. - parse_str($query, $perma_query_vars); - - // If we're processing a 404 request, clear the error var - // since we found something. - if ( isset($_GET['error']) ) - unset($_GET['error']); - - if ( isset($error) ) - unset($error); - - break; + if ( empty( $req_uri ) ) { + if ( isset( $rewrite['$'] ) ) { + $this->matched_rule = '$'; + $query = $rewrite['$']; + $matches = array(''); } + } else if ( $req_uri != 'wp-app.php' ) { + foreach ( (array) $rewrite as $match => $query ) { + // If the requesting file is the anchor of the match, prepend it to the path info. + if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request ) + $request_match = $req_uri . '/' . $request; + + if ( preg_match("#^$match#", $request_match, $matches) || + preg_match("#^$match#", urldecode($request_match), $matches) ) { + // Got a match. + $this->matched_rule = $match; + break; + } + } + } + + if ( isset( $this->matched_rule ) ) { + // Trim the query of everything up to the '?'. + $query = preg_replace("!^.+\?!", '', $query); + + // Substitute the substring matches into the query. + $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); + + $this->matched_query = $query; + + // Parse the query. + parse_str($query, $perma_query_vars); + + // If we're processing a 404 request, clear the error var + // since we found something. + unset( $_GET['error'] ); + unset( $error ); } // If req_uri is empty or if it is a request for ourself, unset error. if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) { - if ( isset($_GET['error']) ) - unset($_GET['error']); - - if ( isset($error) ) - unset($error); + unset( $_GET['error'] ); + unset( $error ); if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) - unset($perma_query_vars); + unset( $perma_query_vars ); $this->did_permalink = false; }