* Fix fallback implementation of mb_strlen so it works and isn't insanely
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 9 Mar 2007 16:22:24 +0000 (16:22 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 9 Mar 2007 16:22:24 +0000 (16:22 +0000)
  slow for large strings, since it's used for page edit lengths

RELEASE-NOTES
includes/GlobalFunctions.php

index 151c578..33f896a 100644 (file)
@@ -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 ==
 
index 61b930d..19eb4be 100644 (file)
@@ -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;
        }
 }