From 6e0cc83a924bf9b5f90ae80f11ccdcf58ee415a7 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 27 Aug 2006 17:33:52 +0200 Subject: add function result caching for cleanID and wikiFN darcs-hash:20060827153352-9b6ab-651decb2566f16334218c6782edc6c7d47b41e13.gz --- inc/pageutils.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'inc/pageutils.php') diff --git a/inc/pageutils.php b/inc/pageutils.php index c2cd29bf1..02330e2a4 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -65,19 +65,26 @@ function getID($param='id',$clean=true){ * converted to unaccented ones * * @author Andreas Gohr - * @param string $id The pageid to clean - * @param boolean $ascii Force ASCII + * @param string $raw_id The pageid to clean + * @param boolean $ascii Force ASCII */ -function cleanID($id,$ascii=false){ +function cleanID($raw_id,$ascii=false){ global $conf; global $lang; static $sepcharpat = null; + static $cache = array(); + + // check if it's already in the memory cache + if (isset($cache[$raw_id])) { + return $cache[$raw_id]; + } + $sepchar = $conf['sepchar']; if($sepcharpat == null) // build string only once to save clock cycles $sepcharpat = '#\\'.$sepchar.'+#'; - $id = trim($id); + $id = trim($raw_id); $id = utf8_strtolower($id); //alternative namespace seperator @@ -102,6 +109,7 @@ function cleanID($id,$ascii=false){ $id = trim($id,':._-'); $id = preg_replace('#:[:\._\-]+#',':',$id); + $cache[$raw_id] = $id; return($id); } @@ -140,8 +148,16 @@ function noNS($id) { * * @author Andreas Gohr */ -function wikiFN($id,$rev='',$clean=true){ +function wikiFN($raw_id,$rev='',$clean=true){ global $conf; + + static $cache = array(); + if (isset($cache[$raw_id]) && isset($cache[$raw_id][$rev])) { + return $cache[$raw_id][$rev]; + } + + $id = $raw_id; + if ($clean) $id = cleanID($id); $id = str_replace(':','/',$id); if(empty($rev)){ @@ -160,6 +176,8 @@ function wikiFN($id,$rev='',$clean=true){ } } } + + $cache[$raw_id][$rev] = $fn; return $fn; } -- cgit v1.2.3