From 15d572da4c2488acc6956dcaa76157da0781f03a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 8 Jul 2015 18:36:49 +0200 Subject: [PATCH] Use 4 byte integer from raw md5 instead of 5 hex representation chars The hash is necessary as comparisons are significantly too slow otherwise. The old hash function used substr on the hexadecimal representation of the md5 hash, rather than the raw binary output. This wastes a significant amount of memory, as each byte can only be used to store up to 4 bit of information. The new hash has 32bit instead of 20bit and uses only a 4 byte integer instead of a 5 byte string. --- src/Composer/DependencyResolver/Rule.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 37db43745..fe5085ae4 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -55,12 +55,11 @@ class Rule $this->reasonData = $reasonData; $this->disabled = false; - $this->job = $job; - $this->type = -1; - $this->ruleHash = substr(md5(implode(',', $this->literals)), 0, 5); + $data = unpack('ihash', md5(implode(',', $this->literals), true)); + $this->ruleHash = $data['hash']; } public function getHash()