From 26afd115b15828ace41792658c43b150651ba4d3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 23 Nov 2004 06:38:11 +0000 Subject: [PATCH] Inner loop optimization: when rendering a wiki page, Language::ucfirst() gets called for every link. Using the faster ASCII function when possible saves a little time on longer pages. --- languages/LanguageUtf8.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/languages/LanguageUtf8.php b/languages/LanguageUtf8.php index 4bd1f66849..aa7ec68d51 100644 --- a/languages/LanguageUtf8.php +++ b/languages/LanguageUtf8.php @@ -36,15 +36,24 @@ class LanguageUtf8 extends Language { # it should be dealt with in Language classes. function ucfirst( $string ) { - if (function_exists('mb_strtoupper')) { - return mb_strtoupper(mb_substr($string,0,1)).mb_substr($string,1); - } else { - global $wikiUpperChars; - return preg_replace ( - "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", - "strtr ( \"\$1\" , \$wikiUpperChars )", - $string ); + /** + * On pages with many links we can get called a lot. + * The multibyte uppercase functions are relatively + * slow, so check first if we can use a faster ASCII + * version instead; it saves a few milliseconds. + */ + if( preg_match( '/^[\x80-\xff]/', $string ) ) { + if (function_exists('mb_strtoupper')) { + return mb_strtoupper(mb_substr($string,0,1)).mb_substr($string,1); + } else { + global $wikiUpperChars; + return preg_replace ( + "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e", + "strtr ( \"\$1\" , \$wikiUpperChars )", + $string ); + } } + return ucfirst( $string ); } function lcfirst( $string ) { -- 2.20.1