Merge "Small optimization for FileContentsHasher"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 7 Oct 2015 15:25:58 +0000 (15:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 7 Oct 2015 15:25:58 +0000 (15:25 +0000)
includes/utils/FileContentsHasher.php

index 655c1d0..c866919 100644 (file)
@@ -57,7 +57,7 @@ class FileContentsHasher {
         * @return string|bool Hash of file contents, or false if the file could not be read.
         */
        public function getFileContentsHashInternal( $filePath, $algo = 'md4' ) {
-               $mtime = MediaWiki\quietCall( 'filemtime', $filePath );
+               $mtime = filemtime( $filePath );
                if ( $mtime === false ) {
                        return false;
                }
@@ -69,7 +69,7 @@ class FileContentsHasher {
                        return $hash;
                }
 
-               $contents = MediaWiki\quietCall( 'file_get_contents', $filePath );
+               $contents = file_get_contents( $filePath );
                if ( $contents === false ) {
                        return false;
                }
@@ -96,8 +96,12 @@ class FileContentsHasher {
                        $filePaths = (array)$filePaths;
                }
 
+               MediaWiki\suppressWarnings();
+
                if ( count( $filePaths ) === 1 ) {
-                       return $instance->getFileContentsHashInternal( $filePaths[0], $algo );
+                       $hash = $instance->getFileContentsHashInternal( $filePaths[0], $algo );
+                       MediaWiki\restoreWarnings();
+                       return $hash;
                }
 
                sort( $filePaths );
@@ -105,6 +109,8 @@ class FileContentsHasher {
                        return $instance->getFileContentsHashInternal( $filePath, $algo ) ?: '';
                }, $filePaths );
 
+               MediaWiki\restoreWarnings();
+
                $hashes = implode( '', $hashes );
                return $hashes ? hash( $algo, $hashes ) : false;
        }