Mercurial > hg-stable
changeset 45648:1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
This is not done for the `dirstate-tree` feature, since it lacks `iter_mut`.
Differential Revision: https://phab.mercurial-scm.org/D9136
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 01 Oct 2020 09:48:41 +0200 |
parents | 7baf5f798ba9 |
children | 9fead7d97069 |
files | rust/hg-core/src/dirstate/parsers.rs |
diffstat | 1 files changed, 5 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/parsers.rs Tue Oct 06 02:21:14 2020 +0200 +++ b/rust/hg-core/src/dirstate/parsers.rs Thu Oct 01 09:48:41 2020 +0200 @@ -107,12 +107,11 @@ let expected_size = expected_size + PARENT_SIZE * 2; let mut packed = Vec::with_capacity(expected_size); - let mut new_state_map = vec![]; packed.extend(&parents.p1); packed.extend(&parents.p2); - for (filename, entry) in state_map.iter() { + for (filename, entry) in state_map.iter_mut() { let new_filename = filename.to_owned(); let mut new_mtime: i32 = entry.mtime; if entry.state == EntryState::Normal && entry.mtime == now { @@ -126,13 +125,10 @@ // contents of the file if the size is the same. This prevents // mistakenly treating such files as clean. new_mtime = -1; - new_state_map.push(( - filename.to_owned(), - DirstateEntry { - mtime: new_mtime, - ..*entry - }, - )); + *entry = DirstateEntry { + mtime: new_mtime, + ..*entry + }; } let mut new_filename = new_filename.into_vec(); if let Some(copy) = copy_map.get(filename) { @@ -152,8 +148,6 @@ return Err(DirstatePackError::BadSize(expected_size, packed.len())); } - state_map.extend(new_state_map); - Ok(packed) } /// `now` is the duration in seconds since the Unix epoch