resourceloader: Tiny optimization to ResourceLoader::isValidModuleName()
authorOri Livneh <ori@wikimedia.org>
Mon, 5 Oct 2015 18:39:13 +0000 (11:39 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 5 Oct 2015 19:34:51 +0000 (19:34 +0000)
This is a micro-optimization, but ResourceLoader is so well-optimized at this
point that the call to PCRE accounts for 1.25% of all load.php CPU time. So
might as well making it a tiny bit faster.

Change-Id: Iefab804a6ca6d54ce230958513a3bea44f4e7c62

includes/resourceloader/ResourceLoader.php

index 002b4ea..77ceff6 100644 (file)
@@ -1580,7 +1580,7 @@ MESSAGE;
         * @return bool Whether $moduleName is a valid module name
         */
        public static function isValidModuleName( $moduleName ) {
         * @return bool Whether $moduleName is a valid module name
         */
        public static function isValidModuleName( $moduleName ) {
-               return !preg_match( '/[|,!]/', $moduleName ) && strlen( $moduleName ) <= 255;
+               return strcspn( $moduleName, '!,|', 0, 255 ) === strlen( $moduleName );
        }
 
        /**
        }
 
        /**