##// 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 /// names. However `BTreeMap` would waste time always re-comparing the same
45 /// names. However `BTreeMap` would waste time always re-comparing the same
46 /// string prefix.
46 /// string prefix.
47 pub(super) type ChildNodes<'on_disk> =
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 /// Represents a file or a directory
50 /// Represents a file or a directory
51 #[derive(Default)]
51 #[derive(Default)]
@@ -99,9 +99,10 b" impl<'on_disk> DirstateMap<'on_disk> {"
99 self.on_disk,
99 self.on_disk,
100 |path, entry, copy_source| {
100 |path, entry, copy_source| {
101 let tracked = entry.state.is_tracked();
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 &mut self.root,
103 &mut self.root,
104 path,
104 path,
105 WithBasename::to_cow_borrowed,
105 |ancestor| {
106 |ancestor| {
106 if tracked {
107 if tracked {
107 ancestor.tracked_descendants_count += 1
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 root: &'tree mut ChildNodes<'on_disk>,
186 root: &'tree mut ChildNodes<'on_disk>,
186 path: &HgPath,
187 path: &'path HgPath,
187 ) -> &'tree mut Node<'on_disk> {
188 to_cow: impl Fn(
188 Self::get_or_insert_node_tracing_ancestors(root, path, |_| {})
189 WithBasename<&'path HgPath>,
189 }
190 ) -> WithBasename<Cow<'on_disk, HgPath>>,
190
191 fn get_or_insert_node_tracing_ancestors<'tree>(
192 root: &'tree mut ChildNodes<'on_disk>,
193 path: &HgPath,
194 mut each_ancestor: impl FnMut(&mut Node),
191 mut each_ancestor: impl FnMut(&mut Node),
195 ) -> &'tree mut Node<'on_disk> {
192 ) -> &'tree mut Node<'on_disk> {
196 let mut child_nodes = root;
193 let mut child_nodes = root;
@@ -204,7 +201,7 b" impl<'on_disk> DirstateMap<'on_disk> {"
204 // map already contains that key, without introducing double
201 // map already contains that key, without introducing double
205 // lookup?
202 // lookup?
206 let child_node =
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 if let Some(next) = inclusive_ancestor_paths.next() {
205 if let Some(next) = inclusive_ancestor_paths.next() {
209 each_ancestor(child_node);
206 each_ancestor(child_node);
210 ancestor_path = next;
207 ancestor_path = next;
@@ -228,9 +225,10 b" impl<'on_disk> DirstateMap<'on_disk> {"
228 _ => 0,
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 &mut self.root,
229 &mut self.root,
233 path,
230 path,
231 WithBasename::to_cow_owned,
234 |ancestor| {
232 |ancestor| {
235 // We can’t use `+= increment` because the counter is unsigned,
233 // We can’t use `+= increment` because the counter is unsigned,
236 // and we want debug builds to detect accidental underflow
234 // and we want debug builds to detect accidental underflow
@@ -593,7 +591,12 b" impl<'on_disk> super::dispatch::Dirstate"
593 key: HgPathBuf,
591 key: HgPathBuf,
594 value: HgPathBuf,
592 value: HgPathBuf,
595 ) -> Option<HgPathBuf> {
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 if node.copy_source.is_none() {
600 if node.copy_source.is_none() {
598 self.nodes_with_copy_source_count += 1
601 self.nodes_with_copy_source_count += 1
599 }
602 }
@@ -1,5 +1,5 b''
1 use crate::utils::hg_path::HgPath;
1 use crate::utils::hg_path::HgPath;
2 use std::borrow::Borrow;
2 use std::borrow::{Borrow, Cow};
3
3
4 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
4 /// Wraps `HgPath` or `HgPathBuf` to make it behave "as" its last path
5 /// component, a.k.a. its base name (as in Python’s `os.path.basename`), but
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> {
84 impl<'a> WithBasename<&'a HgPath> {
85 pub fn to_owned(&self) -> WithBasename<T::Owned> {
85 pub fn to_cow_borrowed(self) -> WithBasename<Cow<'a, HgPath>> {
86 WithBasename {
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 base_name_start: self.base_name_start,
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