From: Timo Tijhof Date: Sat, 25 Mar 2017 03:20:44 +0000 (-0700) Subject: resourceloader: Optimise getMimeType() for common case X-Git-Tag: 1.31.0-rc.0~3688^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=f02454b12ca961aee2fa6e9085a0918cd24ce523 resourceloader: Optimise getMimeType() for common case About 0.74% of load.php is spent in CSSMin::getMimeType/finfo_file. We don't apply this to user-generated content of external urls, only local files in version control. And in terms of correctness, we don't support misleading file names, so it's not a problem that a foo.png containing XML/SVG content would get the wrong mime-type when base64 embedding it in CSS. Change-Id: I17686467c897984117671098e94db8732446dc75 --- diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index b1cece8488..bba07e263b 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -176,6 +176,12 @@ class CSSMin { * @return bool|string */ public static function getMimeType( $file ) { + // Infer the MIME-type from the file extension + $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ); + if ( isset( self::$mimeTypes[$ext] ) ) { + return self::$mimeTypes[$ext]; + } + $realpath = realpath( $file ); if ( $realpath @@ -186,12 +192,6 @@ class CSSMin { return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath ); } - // Infer the MIME-type from the file extension - $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ); - if ( isset( self::$mimeTypes[$ext] ) ) { - return self::$mimeTypes[$ext]; - } - return false; }