From 5d8b5d197d749bd1dbd67a61dbae48ca62806e8a Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 25 May 2022 11:17:22 +0200 Subject: [PATCH] micro-optimize condition https://github.com/vimeo/psalm/pull/7997#pullrequestreview-983975049 --- .../Internal/Provider/ClassLikeStorageCacheProvider.php | 7 +++---- src/Psalm/Internal/Provider/FileStorageCacheProvider.php | 7 +++---- src/Psalm/Internal/Provider/ProjectCacheProvider.php | 5 ++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php index 23b97d594..0c79452a6 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php @@ -18,14 +18,13 @@ use function igbinary_serialize; use function igbinary_unserialize; use function is_dir; use function mkdir; -use function phpversion; use function serialize; use function strtolower; use function unlink; use function unserialize; -use function version_compare; use const DIRECTORY_SEPARATOR; +use const PHP_VERSION_ID; /** * @internal @@ -114,7 +113,7 @@ class ClassLikeStorageCacheProvider private function getCacheHash(?string $file_path, ?string $file_contents): string { $data = ($file_path ? $file_contents : '') . $this->modified_timestamps; - return version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data); + return PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data); } /** @@ -166,7 +165,7 @@ class ClassLikeStorageCacheProvider $data = $file_path ? strtolower($file_path) . ' ' : ''; $data .= $fq_classlike_name_lc; - $file_path_sha = version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data); + $file_path_sha = PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data); return $parser_cache_directory . DIRECTORY_SEPARATOR diff --git a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php index 77021e186..5d4a5b29b 100644 --- a/src/Psalm/Internal/Provider/FileStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileStorageCacheProvider.php @@ -18,14 +18,13 @@ use function igbinary_serialize; use function igbinary_unserialize; use function is_dir; use function mkdir; -use function phpversion; use function serialize; use function strtolower; use function unlink; use function unserialize; -use function version_compare; use const DIRECTORY_SEPARATOR; +use const PHP_VERSION_ID; /** * @internal @@ -121,7 +120,7 @@ class FileStorageCacheProvider private function getCacheHash(string $file_path, string $file_contents): string { $data = ($file_path ? $file_contents : '') . $this->modified_timestamps; - return version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data); + return PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data); } /** @@ -168,7 +167,7 @@ class FileStorageCacheProvider mkdir($parser_cache_directory, 0777, true); } - if (version_compare(phpversion(), '8.1', '>=')) { + if (PHP_VERSION_ID >= 80100) { $hash = hash('xxh128', $file_path); } else { $hash = hash('md4', $file_path); diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index d8763ca95..57755770d 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -10,11 +10,10 @@ use function file_put_contents; use function filemtime; use function hash; use function mkdir; -use function phpversion; use function touch; -use function version_compare; use const DIRECTORY_SEPARATOR; +use const PHP_VERSION_ID; /** * Used to determine which files reference other files, necessary for using the --diff @@ -93,7 +92,7 @@ class ProjectCacheProvider return true; } - if (version_compare(phpversion(), '8.1', '>=')) { + if (PHP_VERSION_ID >= 80100) { $hash = hash('xxh128', $lockfile_contents); } else { $hash = hash('md4', $lockfile_contents);