comparison rust/hg-core/src/dirstate/dirs_multiset.rs @ 47332:4ee9f419c52e

rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs This will enable the tree-based DirstateMap to not always have an actual DirstateEntry in memory for all nodes, but construct it on demand. Differential Revision: https://phab.mercurial-scm.org/D10746
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 19 May 2021 13:15:00 +0200
parents cd8ca38fccff
children ed1583a845d2
comparison
equal deleted inserted replaced
47331:0252600fd1cf 47332:4ee9f419c52e
28 28
29 impl DirsMultiset { 29 impl DirsMultiset {
30 /// Initializes the multiset from a dirstate. 30 /// Initializes the multiset from a dirstate.
31 /// 31 ///
32 /// If `skip_state` is provided, skips dirstate entries with equal state. 32 /// If `skip_state` is provided, skips dirstate entries with equal state.
33 pub fn from_dirstate<'a, I, P>( 33 pub fn from_dirstate<I, P>(
34 dirstate: I, 34 dirstate: I,
35 skip_state: Option<EntryState>, 35 skip_state: Option<EntryState>,
36 ) -> Result<Self, DirstateMapError> 36 ) -> Result<Self, DirstateMapError>
37 where 37 where
38 I: IntoIterator<Item = (P, &'a DirstateEntry)>, 38 I: IntoIterator<Item = (P, DirstateEntry)>,
39 P: AsRef<HgPath>, 39 P: AsRef<HgPath>,
40 { 40 {
41 let mut multiset = DirsMultiset { 41 let mut multiset = DirsMultiset {
42 inner: FastHashMap::default(), 42 inner: FastHashMap::default(),
43 }; 43 };
336 inner: FastHashMap::default(), 336 inner: FastHashMap::default(),
337 }; 337 };
338 assert_eq!(expected, new); 338 assert_eq!(expected, new);
339 339
340 let new = 340 let new =
341 DirsMultiset::from_dirstate(&StateMap::default(), None).unwrap(); 341 DirsMultiset::from_dirstate(StateMap::default(), None).unwrap();
342 let expected = DirsMultiset { 342 let expected = DirsMultiset {
343 inner: FastHashMap::default(), 343 inner: FastHashMap::default(),
344 }; 344 };
345 assert_eq!(expected, new); 345 assert_eq!(expected, new);
346 } 346 }
379 let expected_inner = [("", 2), ("a", 2), ("b", 1), ("a/d", 1)] 379 let expected_inner = [("", 2), ("a", 2), ("b", 1), ("a/d", 1)]
380 .iter() 380 .iter()
381 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) 381 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v))
382 .collect(); 382 .collect();
383 383
384 let new = DirsMultiset::from_dirstate(&input_map, None).unwrap(); 384 let new = DirsMultiset::from_dirstate(input_map, None).unwrap();
385 let expected = DirsMultiset { 385 let expected = DirsMultiset {
386 inner: expected_inner, 386 inner: expected_inner,
387 }; 387 };
388 assert_eq!(expected, new); 388 assert_eq!(expected, new);
389 } 389 }
415 .iter() 415 .iter()
416 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v)) 416 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v))
417 .collect(); 417 .collect();
418 418
419 let new = 419 let new =
420 DirsMultiset::from_dirstate(&input_map, Some(EntryState::Normal)) 420 DirsMultiset::from_dirstate(input_map, Some(EntryState::Normal))
421 .unwrap(); 421 .unwrap();
422 let expected = DirsMultiset { 422 let expected = DirsMultiset {
423 inner: expected_inner, 423 inner: expected_inner,
424 }; 424 };
425 assert_eq!(expected, new); 425 assert_eq!(expected, new);