##// END OF EJS Templates
dirstate-tree: Extract into a method sorting children of a given node...
Simon Sapin -
r48057:ce41ee53 default
parent child Browse files
Show More
@@ -45,10 +45,11 b" pub struct DirstateMap<'on_disk> {"
45 45 /// Using a plain `HgPathBuf` of the full path from the repository root as a
46 46 /// map key would also work: all paths in a given map have the same parent
47 47 /// path, so comparing full paths gives the same result as comparing base
48 /// names. However `BTreeMap` would waste time always re-comparing the same
48 /// names. However `HashMap` would waste time always re-hashing the same
49 49 /// string prefix.
50 pub(super) type NodeKey<'on_disk> = WithBasename<Cow<'on_disk, HgPath>>;
50 51 pub(super) type ChildNodes<'on_disk> =
51 FastHashMap<WithBasename<Cow<'on_disk, HgPath>>, Node<'on_disk>>;
52 FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>;
52 53
53 54 /// Represents a file or a directory
54 55 #[derive(Default)]
@@ -64,10 +65,20 b" pub(super) struct Node<'on_disk> {"
64 65 tracked_descendants_count: usize,
65 66 }
66 67
67 impl Node<'_> {
68 impl<'on_disk> Node<'on_disk> {
68 69 pub(super) fn state(&self) -> Option<EntryState> {
69 70 self.entry.as_ref().map(|entry| entry.state)
70 71 }
72
73 pub(super) fn sorted<'tree>(
74 nodes: &'tree mut ChildNodes<'on_disk>,
75 ) -> Vec<(&'tree NodeKey<'on_disk>, &'tree mut Self)> {
76 let mut vec: Vec<_> = nodes.iter_mut().collect();
77 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value:
78 // https://github.com/rust-lang/rust/issues/34162
79 vec.sort_unstable_by(|(path1, _), (path2, _)| path1.cmp(path2));
80 vec
81 }
71 82 }
72 83
73 84 /// `(full_path, entry, copy_source)`
@@ -110,11 +110,9 b" impl<'tree, 'a> StatusCommon<'tree, 'a> "
110 110
111 111 // `merge_join_by` requires both its input iterators to be sorted:
112 112
113 let mut dirstate_nodes: Vec<_> = dirstate_nodes.iter_mut().collect();
113 let dirstate_nodes = Node::sorted(dirstate_nodes);
114 114 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value:
115 115 // https://github.com/rust-lang/rust/issues/34162
116 dirstate_nodes
117 .sort_unstable_by(|(path1, _), (path2, _)| path1.cmp(path2));
118 116 fs_entries.sort_unstable_by(|e1, e2| e1.base_name.cmp(&e2.base_name));
119 117
120 118 itertools::merge_join_by(
General Comments 0
You need to be logged in to leave comments. Login now