From 1ec3e290b9b9a8a8d04a93cd1bc450ce8cfd3b52 Mon Sep 17 00:00:00 2001 From: croxton Date: Mon, 25 Jan 2016 10:31:02 +0000 Subject: [PATCH] Caching result of call to EE_URI when parsing @URI pointer in context parameter, to avoid redundant object instantiation. Fixes #140 --- .../third_party/stash/mod.stash.php | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/system/expressionengine/third_party/stash/mod.stash.php b/system/expressionengine/third_party/stash/mod.stash.php index da40496..35467d7 100755 --- a/system/expressionengine/third_party/stash/mod.stash.php +++ b/system/expressionengine/third_party/stash/mod.stash.php @@ -4086,16 +4086,25 @@ private function _parse_context($name, $disable_query_str = FALSE) } // fetch the *unadulterated* URI of the current page - $ee_uri = new EE_URI; + if ( isset(self::$_cache['uri'])) + { + $uri = self::$_cache['uri']; // retrieve from cache if we've done this before + } + else + { + $ee_uri = new EE_URI; + + // documented as a 'private' method, but not actually. Called in CI_Router so unlikely to ever be made private. + $ee_uri->_fetch_uri_string(); + $ee_uri->_remove_url_suffix(); + $ee_uri->_explode_segments(); - // documented as a 'private' method, but not actually. Called in CI_Router so unlikely to ever be made private. - $ee_uri->_fetch_uri_string(); - $ee_uri->_remove_url_suffix(); - $ee_uri->_explode_segments(); + // provide a fallback value for index pages + $uri = $ee_uri->uri_string(); + $uri = empty($uri) ? $this->EE->stash_model->get_index_key() : $uri; - // provide a fallback value for index pages - $uri = $ee_uri->uri_string(); - $uri = empty($uri) ? $this->EE->stash_model->get_index_key() : $uri; + self::$_cache['uri'] = $uri; // cache the value + } // append query string? if ($this->include_query_str