wfIniGetBool: reduce strtolower() calls
authorAntoine Musso <hashar@free.fr>
Wed, 29 May 2013 09:16:25 +0000 (11:16 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 29 May 2013 10:51:01 +0000 (10:51 +0000)
We were calling strtolower() up to three times. As a micro optimization,
call it once around ini_get() and do the logical checks against the
variable containing the lower case output.

Change-Id: I16c149fbb9de84d7b6f3e68da06de208c5572b7c

includes/GlobalFunctions.php

index 78fcb8b..1c6f642 100644 (file)
@@ -2593,11 +2593,11 @@ function in_string( $needle, $str, $insensitive = false ) {
  * @return Bool
  */
 function wfIniGetBool( $setting ) {
-       $val = ini_get( $setting );
+       $val = strtolower( ini_get( $setting ) );
        // 'on' and 'true' can't have whitespace around them, but '1' can.
-       return strtolower( $val ) == 'on'
-               || strtolower( $val ) == 'true'
-               || strtolower( $val ) == 'yes'
+       return $val == 'on'
+               || $val == 'true'
+               || $val == 'yes'
                || preg_match( "/^\s*[+-]?0*[1-9]/", $val ); // approx C atoi() function
 }