瀏覽代碼

Use a block cache in _find_content_rename_candidates().

This will improve the performance of calls to changes_with_renames(), (which calls _find_content_rename_candidates), by avoiding re-hashing in _similarity_score().
Mike Williams 10 年之前
父節點
當前提交
6eed06915f
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 3 0
      NEWS
  2. 3 2
      dulwich/diff_tree.py

+ 3 - 0
NEWS

@@ -8,6 +8,9 @@
   * Fix running of testsuite when installed.
     (Jelmer Vernooij, #223)
 
+  * Use a block cache in _find_content_rename_candidates(),
+    improving performance. (Mike Williams)
+
 0.9.8	2014-11-30
 
  BUG FIXES

+ 3 - 2
dulwich/diff_tree.py

@@ -504,19 +504,20 @@ class RenameDetector(object):
         if not self._should_find_content_renames():
             return
 
+        block_cache = {}
         check_paths = self._rename_threshold is not None
         for delete in self._deletes:
             if S_ISGITLINK(delete.old.mode):
                 continue  # Git links don't exist in this repo.
             old_sha = delete.old.sha
             old_obj = self._store[old_sha]
-            old_blocks = _count_blocks(old_obj)
+            block_cache[old_sha] = _count_blocks(old_obj)
             for add in self._adds:
                 if stat.S_IFMT(delete.old.mode) != stat.S_IFMT(add.new.mode):
                     continue
                 new_obj = self._store[add.new.sha]
                 score = _similarity_score(old_obj, new_obj,
-                                          block_cache={old_sha: old_blocks})
+                                          block_cache=block_cache)
                 if score > self._rename_threshold:
                     new_type = self._rename_type(check_paths, delete, add)
                     rename = TreeChange(new_type, delete.old, add.new)