Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/dirstate/parsers.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 | d6c94ca40863 |
children | 73f23e7610f8 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/parsers.rs Fri Apr 30 18:24:54 2021 +0200 +++ b/rust/hg-core/src/dirstate/parsers.rs Fri Apr 30 19:57:46 2021 +0200 @@ -4,7 +4,7 @@ // GNU General Public License version 2 or any later version. use crate::errors::HgError; -use crate::utils::hg_path::{HgPath, HgPathBuf}; +use crate::utils::hg_path::HgPath; use crate::{ dirstate::{CopyMap, EntryState, RawEntry, StateMap}, DirstateEntry, DirstateParents, @@ -83,8 +83,8 @@ } fn packed_filename_and_copy_source_size( - filename: &HgPathBuf, - copy_source: Option<&HgPathBuf>, + filename: &HgPath, + copy_source: Option<&HgPath>, ) -> usize { filename.len() + if let Some(source) = copy_source { @@ -95,17 +95,17 @@ } pub fn packed_entry_size( - filename: &HgPathBuf, - copy_source: Option<&HgPathBuf>, + filename: &HgPath, + copy_source: Option<&HgPath>, ) -> usize { MIN_ENTRY_SIZE + packed_filename_and_copy_source_size(filename, copy_source) } pub fn pack_entry( - filename: &HgPathBuf, + filename: &HgPath, entry: &DirstateEntry, - copy_source: Option<&HgPathBuf>, + copy_source: Option<&HgPath>, packed: &mut Vec<u8>, ) { let length = packed_filename_and_copy_source_size(filename, copy_source); @@ -159,7 +159,7 @@ let expected_size: usize = state_map .iter() .map(|(filename, _)| { - packed_entry_size(filename, copy_map.get(filename)) + packed_entry_size(filename, copy_map.get(filename).map(|p| &**p)) }) .sum(); let expected_size = expected_size + PARENT_SIZE * 2; @@ -171,7 +171,12 @@ for (filename, entry) in state_map.iter_mut() { clear_ambiguous_mtime(entry, now); - pack_entry(filename, entry, copy_map.get(filename), &mut packed) + pack_entry( + filename, + entry, + copy_map.get(filename).map(|p| &**p), + &mut packed, + ) } if packed.len() != expected_size {