Ver código fonte

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.
Nils Adermann 9 anos atrás
pai
commit
15d572da4c
1 arquivos alterados com 2 adições e 3 exclusões
  1. 2 3
      src/Composer/DependencyResolver/Rule.php

+ 2 - 3
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()