##// END OF EJS Templates
dirstate-tree: Borrow paths from the "on disk" bytes...
Simon Sapin -
r47896:ecfe0819 default
parent child Browse files
Show More
@@ -45,7 +45,7 b" pub struct DirstateMap<'on_disk> {"
45 45 /// names. However `BTreeMap` would waste time always re-comparing the same
46 46 /// string prefix.
47 47 pub(super) type ChildNodes<'on_disk> =
48 FastHashMap<WithBasename<HgPathBuf>, Node<'on_disk>>;
48 FastHashMap<WithBasename<Cow<'on_disk, HgPath>>, Node<'on_disk>>;
49 49
50 50 /// Represents a file or a directory
51 51 #[derive(Default)]
@@ -99,9 +99,10 b" impl<'on_disk> DirstateMap<'on_disk> {"
99 99 self.on_disk,
100 100 |path, entry, copy_source| {
101 101 let tracked = entry.state.is_tracked();
102 let node = Self::get_or_insert_node_tracing_ancestors(
102 let node = Self::get_or_insert_node(
103 103 &mut self.root,
104 104 path,
105 WithBasename::to_cow_borrowed,
105 106 |ancestor| {
106 107 if tracked {
107 108 ancestor.tracked_descendants_count += 1
@@ -181,16 +182,12 b" impl<'on_disk> DirstateMap<'on_disk> {"
181 182 }
182 183 }
183 184
184 fn get_or_insert_node<'tree>(
185 fn get_or_insert_node<'tree, 'path>(
185 186 root: &'tree mut ChildNodes<'on_disk>,
186 path: &HgPath,
187 ) -> &'tree mut Node<'on_disk> {
188 Self::get_or_insert_node_tracing_ancestors(root, path, |_| {})
189 }
190
191 fn get_or_insert_node_tracing_ancestors<'tree>(
192 root: &'tree mut ChildNodes<'on_disk>,
193 path: &HgPath,
187 path: &'path HgPath,
188 to_cow: impl Fn(
189 WithBasename<&'path HgPath>,
190 ) -> WithBasename<Cow<'on_disk, HgPath>>,
194 191 mut each_ancestor: impl FnMut(&mut Node),
195 192 ) -> &'tree mut Node<'on_disk> {
196 193 let mut child_nodes = root;
@@ -204,7 +201,7 b" impl<'on_disk> DirstateMap<'on_disk> {"
204 201 // map already contains that key, without introducing double
205 202 // lookup?
206 203 let child_node =
207 child_nodes.entry(ancestor_path.to_owned()).or_default();
204 child_nodes.entry(to_cow(ancestor_path)).or_default();
208 205 if let Some(next) = inclusive_ancestor_paths.next() {
209 206 each_ancestor(child_node);
210 207 ancestor_path = next;
@@ -228,9 +225,10 b" impl<'on_disk> DirstateMap<'on_disk> {"
228 225 _ => 0,
229 226 };
230 227
231 let node = Self::get_or_insert_node_tracing_ancestors(
228 let node = Self::get_or_insert_node(
232 229 &mut self.root,
233 230 path,
231 WithBasename::to_cow_owned,
234 232 |ancestor| {
235 233 // We can’t use `+= increment` because the counter is unsigned,
236 234 // and we want debug builds to detect accidental underflow
@@ -593,7 +591,12 b" impl<'on_disk> super::dispatch::Dirstate"
593 591 key: HgPathBuf,
594 592 value: HgPathBuf,
595 593 ) -> Option<HgPathBuf> {
596 let node = Self::get_or_insert_node(&mut self.root, &key);
594 let node = Self::get_or_insert_node(
595 &mut self.root,
596 &key,
597 WithBasename::to_cow_owned,
598 |_ancestor| {},
599 );
597 600 if node.copy_source.is_none() {
598 601 self.nodes_with_copy_source_count += 1
599 602 }
@@ -1,5 +1,5 b''
1 1 use crate::utils::hg_path::HgPath;
2 use std::borrow::Borrow;
2 use std::borrow::{Borrow, Cow};
3 3
4 4 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
5 5 /// component, a.k.a. its base name (as in Python’s `os.path.basename`), but
@@ -81,10 +81,17 b' impl<T: AsRef<HgPath> + Ord> Ord for Wit'
81 81 }
82 82 }
83 83
84 impl<T: ?Sized + ToOwned> WithBasename<&'_ T> {
85 pub fn to_owned(&self) -> WithBasename<T::Owned> {
84 impl<'a> WithBasename<&'a HgPath> {
85 pub fn to_cow_borrowed(self) -> WithBasename<Cow<'a, HgPath>> {
86 86 WithBasename {
87 full_path: self.full_path.to_owned(),
87 full_path: Cow::Borrowed(self.full_path),
88 base_name_start: self.base_name_start,
89 }
90 }
91
92 pub fn to_cow_owned<'b>(self) -> WithBasename<Cow<'b, HgPath>> {
93 WithBasename {
94 full_path: Cow::Owned(self.full_path.to_owned()),
88 95 base_name_start: self.base_name_start,
89 96 }
90 97 }
General Comments 0
You need to be logged in to leave comments. Login now