From: Brion Vibber Date: Fri, 9 Mar 2007 16:22:24 +0000 (+0000) Subject: * Fix fallback implementation of mb_strlen so it works and isn't insanely X-Git-Tag: 1.31.0-rc.0~53828 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=2c9cb9dcbd5fad07049e91a7ba59613f30106c52;p=lhc%2Fweb%2Fwiklou.git * Fix fallback implementation of mb_strlen so it works and isn't insanely slow for large strings, since it's used for page edit lengths --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 151c57824d..33f896ab0c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -259,6 +259,9 @@ lighter making things easier to read. * (bug 6997) Link from Special:log/block to unblock form * (bug 9117) Link from Special:log/delete to undelete form * Link from Special:log/protect to change protection form +* Fix fallback implementation of mb_strlen so it works and isn't insanely + slow for large strings, since it's used for page edit lengths + == Languages updated == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 61b930d458..19eb4be087 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -62,9 +62,26 @@ if ( !function_exists( 'mb_substr' ) ) { } if ( !function_exists( 'mb_strlen' ) ) { - function mb_strlen( $str, $enc = "" ) { - preg_match_all( '/./us', $str, $matches ); - return count($matches); + /** + * Fallback implementation of mb_strlen, hardcoded to UTF-8. + * @param string $str + * @param string $enc optional encoding; ignored + * @return int + */ + function new_mb_strlen( $str, $enc="" ) { + $counts = count_chars( $str ); + $total = 0; + + // Count ASCII bytes + for( $i = 0; $i < 0x80; $i++ ) { + $total += $counts[$i]; + } + + // Count multibyte sequence heads + for( $i = 0xc0; $i < 0xff; $i++ ) { + $total += $counts[$i]; + } + return $total; } }