1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

only sort when necessary and faster hash

* sort is much more expensive than count, so we only sort if we have something to sort
* could implement for ksort too, but advantage there is minimal since we almost always have more than 1 possibility
* use same hash algorithm as in other places (= faster)
* reduces runtime by 2-3%
This commit is contained in:
kkmuffme 2022-06-28 19:04:09 +02:00
parent 4db928e923
commit 4048bb9d8b

View File

@ -10,15 +10,17 @@ use function array_map;
use function array_unique; use function array_unique;
use function array_values; use function array_values;
use function count; use function count;
use function hash;
use function implode; use function implode;
use function ksort; use function ksort;
use function md5;
use function reset; use function reset;
use function serialize; use function serialize;
use function sort; use function sort;
use function strpos; use function strpos;
use function substr; use function substr;
use const PHP_VERSION_ID;
/** /**
* @internal * @internal
* *
@ -106,11 +108,15 @@ class Clause
} else { } else {
ksort($possibilities); ksort($possibilities);
foreach ($possibilities as $i => $_) { foreach ($possibilities as $i => $v) {
if (count($v) < 2) {
continue;
}
sort($possibilities[$i]); sort($possibilities[$i]);
} }
$this->hash = md5(serialize($possibilities)); $data = serialize($possibilities);
$this->hash = PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data);
} }
} }