浏览代码

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 10 年之前
父节点
当前提交
15d572da4c
共有 1 个文件被更改,包括 2 次插入3 次删除
  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()