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
- # Normalise title-case input
+ # Normalise title-case input (with some inlining)
$lckey = str_replace( ' ', '_', $key );
$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 ) {
# Try the MediaWiki namespace
if( !$this->mDisable && $useDB ) {
}
function ucfirst( $str ) {
}
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 ) {
}
function uc( $str, $first = false ) {
}
function lcfirst( $str ) {
}
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] );
- else return self::lc( $str, true );
}
function lc( $str, $first = false ) {
}
function lc( $str, $first = false ) {