rust/hg-core/src/dirstate_tree/dirstate_map.rs
changeset 47282 ce41ee53263f
parent 47280 1766130fe9ba
child 47283 2a9ddc8094c7
equal deleted inserted replaced
47281:6763913fa175 47282:ce41ee53263f
    43 }
    43 }
    44 
    44 
    45 /// Using a plain `HgPathBuf` of the full path from the repository root as a
    45 /// Using a plain `HgPathBuf` of the full path from the repository root as a
    46 /// map key would also work: all paths in a given map have the same parent
    46 /// map key would also work: all paths in a given map have the same parent
    47 /// path, so comparing full paths gives the same result as comparing base
    47 /// path, so comparing full paths gives the same result as comparing base
    48 /// names. However `BTreeMap` would waste time always re-comparing the same
    48 /// names. However `HashMap` would waste time always re-hashing the same
    49 /// string prefix.
    49 /// string prefix.
       
    50 pub(super) type NodeKey<'on_disk> = WithBasename<Cow<'on_disk, HgPath>>;
    50 pub(super) type ChildNodes<'on_disk> =
    51 pub(super) type ChildNodes<'on_disk> =
    51     FastHashMap<WithBasename<Cow<'on_disk, HgPath>>, Node<'on_disk>>;
    52     FastHashMap<NodeKey<'on_disk>, Node<'on_disk>>;
    52 
    53 
    53 /// Represents a file or a directory
    54 /// Represents a file or a directory
    54 #[derive(Default)]
    55 #[derive(Default)]
    55 pub(super) struct Node<'on_disk> {
    56 pub(super) struct Node<'on_disk> {
    56     /// `None` for directories
    57     /// `None` for directories
    62 
    63 
    63     /// How many (non-inclusive) descendants of this node are tracked files
    64     /// How many (non-inclusive) descendants of this node are tracked files
    64     tracked_descendants_count: usize,
    65     tracked_descendants_count: usize,
    65 }
    66 }
    66 
    67 
    67 impl Node<'_> {
    68 impl<'on_disk> Node<'on_disk> {
    68     pub(super) fn state(&self) -> Option<EntryState> {
    69     pub(super) fn state(&self) -> Option<EntryState> {
    69         self.entry.as_ref().map(|entry| entry.state)
    70         self.entry.as_ref().map(|entry| entry.state)
       
    71     }
       
    72 
       
    73     pub(super) fn sorted<'tree>(
       
    74         nodes: &'tree mut ChildNodes<'on_disk>,
       
    75     ) -> Vec<(&'tree NodeKey<'on_disk>, &'tree mut Self)> {
       
    76         let mut vec: Vec<_> = nodes.iter_mut().collect();
       
    77         // `sort_unstable_by_key` doesn’t allow keys borrowing from the value:
       
    78         // https://github.com/rust-lang/rust/issues/34162
       
    79         vec.sort_unstable_by(|(path1, _), (path2, _)| path1.cmp(path2));
       
    80         vec
    70     }
    81     }
    71 }
    82 }
    72 
    83 
    73 /// `(full_path, entry, copy_source)`
    84 /// `(full_path, entry, copy_source)`
    74 type NodeDataMut<'tree, 'on_disk> = (
    85 type NodeDataMut<'tree, 'on_disk> = (