Lwelling has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/62192


Change subject: Remove reduntant regex from calls to StringUtils::isUtf8()
......................................................................

Remove reduntant regex from calls to StringUtils::isUtf8()

I've cautiously moved the regex out of the most used code path.
There is no string that will match that regex check that will not also be
passed by mb_check_encoding.  I think the regex was intended as a shortcut
evaluation, but it is no faster than mb_check_encoding which will often
need to be run anyway.

I think it could just be deleted, but I have limited motivation to
risk introducing a bug to improve performance on old PHP vesions and
unusual configurations, so I've moved it to the fallback code path.

Change-Id: Ie9425cc23ba032e5aff42beeb44cbb1146050452
---
M includes/StringUtils.php
1 file changed, 6 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/92/62192/1

diff --git a/includes/StringUtils.php b/includes/StringUtils.php
index 48cde0e..8a70cf6 100644
--- a/includes/StringUtils.php
+++ b/includes/StringUtils.php
@@ -48,15 +48,15 @@
         */
        static function isUtf8( $value, $disableMbstring = false ) {
 
-               if ( preg_match( '/[\x80-\xff]/', $value ) === 0 ) {
-                       # no high bit set, this is pure ASCII which is de facto
-                       # valid UTF-8
-                       return true;
-               }
-
                if ( !$disableMbstring && function_exists( 'mb_check_encoding' 
) ) {
                        return mb_check_encoding( $value, 'UTF-8' );
                } else {
+                       if ( preg_match( '/[\x80-\xff]/', $value ) === 0 ) {
+                               # no high bit set, this is pure ASCII which is 
de facto
+                               # valid UTF-8
+                               return true;
+                       }
+
                        $hasUtf8 = preg_match( '/^(?>
                                  [\x00-\x7f]
                                | [\xc0-\xdf][\x80-\xbf]

-- 
To view, visit https://gerrit.wikimedia.org/r/62192
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9425cc23ba032e5aff42beeb44cbb1146050452
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Lwelling <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to