From f02454b12ca961aee2fa6e9085a0918cd24ce523 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 24 Mar 2017 20:20:44 -0700 Subject: [PATCH] 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 --- includes/libs/CSSMin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; } -- 2.20.1