comparison rust/hg-core/src/dirstate_tree/dispatch.rs @ 47138: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
comparison
equal deleted inserted replaced
47137:d8ac62374943 47138:cd8ca38fccff
45 45
46 fn non_normal_entries_remove(&mut self, key: &HgPath); 46 fn non_normal_entries_remove(&mut self, key: &HgPath);
47 47
48 fn non_normal_or_other_parent_paths( 48 fn non_normal_or_other_parent_paths(
49 &mut self, 49 &mut self,
50 ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_>; 50 ) -> Box<dyn Iterator<Item = &HgPath> + '_>;
51 51
52 fn set_non_normal_other_parent_entries(&mut self, force: bool); 52 fn set_non_normal_other_parent_entries(&mut self, force: bool);
53 53
54 fn iter_non_normal_paths( 54 fn iter_non_normal_paths(
55 &mut self, 55 &mut self,
56 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; 56 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
57 57
58 fn iter_non_normal_paths_panic( 58 fn iter_non_normal_paths_panic(
59 &self, 59 &self,
60 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; 60 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
61 61
62 fn iter_other_parent_paths( 62 fn iter_other_parent_paths(
63 &mut self, 63 &mut self,
64 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_>; 64 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_>;
65 65
66 fn has_tracked_dir( 66 fn has_tracked_dir(
67 &mut self, 67 &mut self,
68 directory: &HgPath, 68 directory: &HgPath,
69 ) -> Result<bool, DirstateMapError>; 69 ) -> Result<bool, DirstateMapError>;
95 95
96 fn copy_map_iter(&self) -> CopyMapIter<'_>; 96 fn copy_map_iter(&self) -> CopyMapIter<'_>;
97 97
98 fn copy_map_contains_key(&self, key: &HgPath) -> bool; 98 fn copy_map_contains_key(&self, key: &HgPath) -> bool;
99 99
100 fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf>; 100 fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath>;
101 101
102 fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf>; 102 fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf>;
103 103
104 fn copy_map_insert( 104 fn copy_map_insert(
105 &mut self, 105 &mut self,
161 self.non_normal_entries_remove(key) 161 self.non_normal_entries_remove(key)
162 } 162 }
163 163
164 fn non_normal_or_other_parent_paths( 164 fn non_normal_or_other_parent_paths(
165 &mut self, 165 &mut self,
166 ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_> { 166 ) -> Box<dyn Iterator<Item = &HgPath> + '_> {
167 let (non_normal, other_parent) = 167 let (non_normal, other_parent) =
168 self.get_non_normal_other_parent_entries(); 168 self.get_non_normal_other_parent_entries();
169 Box::new(non_normal.union(other_parent)) 169 Box::new(non_normal.union(other_parent).map(|p| &**p))
170 } 170 }
171 171
172 fn set_non_normal_other_parent_entries(&mut self, force: bool) { 172 fn set_non_normal_other_parent_entries(&mut self, force: bool) {
173 self.set_non_normal_other_parent_entries(force) 173 self.set_non_normal_other_parent_entries(force)
174 } 174 }
175 175
176 fn iter_non_normal_paths( 176 fn iter_non_normal_paths(
177 &mut self, 177 &mut self,
178 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { 178 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
179 let (non_normal, _other_parent) = 179 let (non_normal, _other_parent) =
180 self.get_non_normal_other_parent_entries(); 180 self.get_non_normal_other_parent_entries();
181 Box::new(non_normal.iter()) 181 Box::new(non_normal.iter().map(|p| &**p))
182 } 182 }
183 183
184 fn iter_non_normal_paths_panic( 184 fn iter_non_normal_paths_panic(
185 &self, 185 &self,
186 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { 186 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
187 let (non_normal, _other_parent) = 187 let (non_normal, _other_parent) =
188 self.get_non_normal_other_parent_entries_panic(); 188 self.get_non_normal_other_parent_entries_panic();
189 Box::new(non_normal.iter()) 189 Box::new(non_normal.iter().map(|p| &**p))
190 } 190 }
191 191
192 fn iter_other_parent_paths( 192 fn iter_other_parent_paths(
193 &mut self, 193 &mut self,
194 ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> { 194 ) -> Box<dyn Iterator<Item = &HgPath> + Send + '_> {
195 let (_non_normal, other_parent) = 195 let (_non_normal, other_parent) =
196 self.get_non_normal_other_parent_entries(); 196 self.get_non_normal_other_parent_entries();
197 Box::new(other_parent.iter()) 197 Box::new(other_parent.iter().map(|p| &**p))
198 } 198 }
199 199
200 fn has_tracked_dir( 200 fn has_tracked_dir(
201 &mut self, 201 &mut self,
202 directory: &HgPath, 202 directory: &HgPath,
241 fn copy_map_len(&self) -> usize { 241 fn copy_map_len(&self) -> usize {
242 self.copy_map.len() 242 self.copy_map.len()
243 } 243 }
244 244
245 fn copy_map_iter(&self) -> CopyMapIter<'_> { 245 fn copy_map_iter(&self) -> CopyMapIter<'_> {
246 Box::new(self.copy_map.iter()) 246 Box::new(self.copy_map.iter().map(|(key, value)| (&**key, &**value)))
247 } 247 }
248 248
249 fn copy_map_contains_key(&self, key: &HgPath) -> bool { 249 fn copy_map_contains_key(&self, key: &HgPath) -> bool {
250 self.copy_map.contains_key(key) 250 self.copy_map.contains_key(key)
251 } 251 }
252 252
253 fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf> { 253 fn copy_map_get(&self, key: &HgPath) -> Option<&HgPath> {
254 self.copy_map.get(key) 254 self.copy_map.get(key).map(|p| &**p)
255 } 255 }
256 256
257 fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> { 257 fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> {
258 self.copy_map.remove(key) 258 self.copy_map.remove(key)
259 } 259 }
277 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> { 277 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> {
278 (&**self).get(key) 278 (&**self).get(key)
279 } 279 }
280 280
281 fn iter(&self) -> StateMapIter<'_> { 281 fn iter(&self) -> StateMapIter<'_> {
282 Box::new((&**self).iter()) 282 Box::new((&**self).iter().map(|(key, value)| (&**key, value)))
283 } 283 }
284 } 284 }