Reverted breakage of non-ASCII message keys, Domas says that's not allowed. Optimised...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 28 Aug 2009 17:58:54 +0000 (17:58 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 28 Aug 2009 17:58:54 +0000 (17:58 +0000)
Timings in microseconds for ASCII no-change, ASCII change, non-ASCII no-change, non-ASCII change:
lcfirst: 1.8, 3.6, 21.2, 22.1
ucfirst: 1.5, 2.3, 21.1, 21.7

includes/MessageCache.php
languages/Language.php

index 96c00ac..2928117 100644 (file)
@@ -509,10 +509,15 @@ class MessageCache {
 
                $message = false;
 
-               # Normalise title-case input
+               # Normalise title-case input (with some inlining)
                $lckey = str_replace( ' ', '_', $key );
-               $lckey[0] = strtolower( $lckey[0] );
-               $uckey = ucfirst( $lckey );
+               if ( ord( $key ) < 128 ) {
+                       $lckey[0] = strtolower( $lckey[0] );
+                       $uckey = ucfirst( $lckey );
+               } else {
+                       $lckey = $wgContLang->lcfirst( $lckey );
+                       $uckey = $wgContLang->ucfirst( $lckey );
+               }
 
                # Try the MediaWiki namespace
                if( !$this->mDisable && $useDB ) {
index 19520fa..3386a44 100644 (file)
@@ -1509,9 +1509,15 @@ class Language {
        }
 
        function ucfirst( $str ) {
-               if ( empty($str) ) return $str;
-               if ( ord($str[0]) < 128 ) return ucfirst($str);
-               else return self::uc($str,true); // fall back to more complex logic in case of multibyte strings
+               $o = ord( $str );
+               if ( $o < 96 ) {
+                       return $str;
+               } elseif ( $o < 128 ) {
+                       return ucfirst($str);
+               } else {
+                       // fall back to more complex logic in case of multibyte strings
+                       return self::uc($str,true); 
+               }
        }
 
        function uc( $str, $first = false ) {
@@ -1541,13 +1547,17 @@ class Language {
        }
        
        function lcfirst( $str ) {
-               if ( empty($str) ) return $str;
-               if ( is_string( $str ) && ord($str[0]) < 128 ) {
-                       // editing string in place = cool
-                       $str[0]=strtolower($str[0]);
+               $o = ord( $str );
+               if ( !$o ) {
+                       return strval( $str );
+               } elseif ( $o >= 128 ) {
+                       return self::lc( $str, true );
+               } elseif ( $o > 96 ) {
+                       return $str;
+               } else {
+                       $str[0] = strtolower( $str[0] );
                        return $str;
                }
-               else return self::lc( $str, true );
        }
 
        function lc( $str, $first = false ) {