copies-rust: use the entry API to overwrite deleted entry
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 02 Dec 2020 10:51:40 +0100
changeset 46152 e166e8a035a7
parent 46151 c6bc77f7e593
child 46153 0a721fc457bf
copies-rust: use the entry API to overwrite deleted entry This is more efficient, more idiomatic and more compact. The main motivation for this change is to cleanup that area before start to do "overwrite" tracking. Such tracking will ultimately help to avoid costly is_ancestors call when merging changeset. Differential Revision: https://phab.mercurial-scm.org/D9494
rust/hg-core/src/copy_tracing.rs
--- a/rust/hg-core/src/copy_tracing.rs	Sat Apr 25 12:37:46 2020 +0200
+++ b/rust/hg-core/src/copy_tracing.rs	Wed Dec 02 10:51:40 2020 +0100
@@ -523,13 +523,10 @@
                 // propagate this information when merging two
                 // TimeStampedPathCopies object.
                 let deleted = path_map.tokenize(deleted_path);
-                if copies.contains_key(&deleted) {
-                    let ttpc = TimeStampedPathCopy {
-                        rev: current_rev,
-                        path: None,
-                    };
-                    copies.insert(deleted, ttpc);
-                }
+                copies.entry(deleted).and_modify(|old| {
+                    old.rev = current_rev;
+                    old.path = None;
+                });
             }
         }
     }