Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/dirstate_tree/dispatch.rs @ 47124:cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Getting the former (through `Deref`) is almost the only useful thing one can
do with the latter anyway. With this changes, API become more flexible for the
"provider" of these paths which may store something else that Deref?s to HgPath,
such as `std::borrow::Cow<HgPath>`. Using `Cow` can help reduce memory alloactions
and copying.
Differential Revision: https://phab.mercurial-scm.org/D10558
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 30 Apr 2021 19:57:46 +0200 |
parents | d8ac62374943 |
children | 1766130fe9ba |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs Fri Apr 30 18:24:54 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/dispatch.rs Fri Apr 30 19:57:46 2021 +0200 @@ -47,21 +47,21 @@ fn non_normal_or_other_parent_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_>; + ) -> Box<dyn Iterator<Item = &HgPath> + '_>; fn set_non_normal_other_parent_entries(&mut self, force: bool); fn iter_non_normal_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>; fn iter_non_normal_paths_panic( &self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>; fn iter_other_parent_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>; fn has_tracked_dir( &mut self, @@ -97,7 +97,7 @@ fn copy_map_contains_key(&self, key: &HgPath) -> bool; - fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf>; + fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath>; fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf>; @@ -163,10 +163,10 @@ fn non_normal_or_other_parent_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_> { + ) -> Box<dyn Iterator<Item = &HgPath> + '_> { let (non_normal, other_parent) = self.get_non_normal_other_parent_entries(); - Box::new(non_normal.union(other_parent)) + Box::new(non_normal.union(other_parent).map(|p| &**p)) } fn set_non_normal_other_parent_entries(&mut self, force: bool) { @@ -175,26 +175,26 @@ fn iter_non_normal_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> { let (non_normal, _other_parent) = self.get_non_normal_other_parent_entries(); - Box::new(non_normal.iter()) + Box::new(non_normal.iter().map(|p| &**p)) } fn iter_non_normal_paths_panic( &self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> { let (non_normal, _other_parent) = self.get_non_normal_other_parent_entries_panic(); - Box::new(non_normal.iter()) + Box::new(non_normal.iter().map(|p| &**p)) } fn iter_other_parent_paths( &mut self, - ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { + ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> { let (_non_normal, other_parent) = self.get_non_normal_other_parent_entries(); - Box::new(other_parent.iter()) + Box::new(other_parent.iter().map(|p| &**p)) } fn has_tracked_dir( @@ -243,15 +243,15 @@ } fn copy_map_iter(&self) -> CopyMapIter<'_> { - Box::new(self.copy_map.iter()) + Box::new(self.copy_map.iter().map(|(key, value)| (&**key, &**value))) } fn copy_map_contains_key(&self, key: &HgPath) -> bool { self.copy_map.contains_key(key) } - fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf> { - self.copy_map.get(key) + fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath> { + self.copy_map.get(key).map(|p| &**p) } fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> { @@ -279,6 +279,6 @@ } fn iter(&self) -> StateMapIter<'_> { - Box::new((&**self).iter()) + Box::new((&**self).iter().map(|(key, value)| (&**key, value))) } }