From: gregb_cc Date: Wed, 12 Mar 2003 21:37:05 +0000 (+0000) Subject: speed improvement in smilie_replace. It is now almost as fast (within 5-10%) of X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=690819315138830384b4eb45dd77e65a3866cb1a;p=moodle.git speed improvement in smilie_replace. It is now almost as fast (within 5-10%) of the version that used global smilie definitions. --- diff --git a/lib/weblib.php b/lib/weblib.php index 3a010c1221..e109b8f248 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -474,7 +474,8 @@ function replace_smilies($text) { global $CFG; static $runonce = false; - static $smilies = false; + static $e = array(); + static $img = array(); static $emoticons = array( ':-)' => 'smiley.gif', ':)' => 'smiley.gif', @@ -502,12 +503,13 @@ function replace_smilies($text) { if($runonce == false): foreach ($emoticons as $emoticon => $image){ - $smilies[$emoticon] = "\"$emoticon\"wwwroot}/pix/s/{$image}\">"; + $e[] = $emoticon; + $img[] = "\"$emoticon\"wwwroot}/pix/s/{$image}\">"; } $runonce = true; endif; - return strtr($text, $smilies); + return str_replace($e, $img, $text); } function text_to_html($text, $smiley=true, $para=true) {