Skip to content
Snippets Groups Projects
Commit 1efbc787 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

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
parent 7baf5f79
No related branches found
No related tags found
No related merge requests found
...@@ -107,8 +107,7 @@ ...@@ -107,8 +107,7 @@
let expected_size = expected_size + PARENT_SIZE * 2; let expected_size = expected_size + PARENT_SIZE * 2;
let mut packed = Vec::with_capacity(expected_size); let mut packed = Vec::with_capacity(expected_size);
let mut new_state_map = vec![];
packed.extend(&parents.p1); packed.extend(&parents.p1);
packed.extend(&parents.p2); packed.extend(&parents.p2);
...@@ -111,8 +110,8 @@ ...@@ -111,8 +110,8 @@
packed.extend(&parents.p1); packed.extend(&parents.p1);
packed.extend(&parents.p2); 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 new_filename = filename.to_owned();
let mut new_mtime: i32 = entry.mtime; let mut new_mtime: i32 = entry.mtime;
if entry.state == EntryState::Normal && entry.mtime == now { if entry.state == EntryState::Normal && entry.mtime == now {
...@@ -126,13 +125,10 @@ ...@@ -126,13 +125,10 @@
// contents of the file if the size is the same. This prevents // contents of the file if the size is the same. This prevents
// mistakenly treating such files as clean. // mistakenly treating such files as clean.
new_mtime = -1; new_mtime = -1;
new_state_map.push(( *entry = DirstateEntry {
filename.to_owned(), mtime: new_mtime,
DirstateEntry { ..*entry
mtime: new_mtime, };
..*entry
},
));
} }
let mut new_filename = new_filename.into_vec(); let mut new_filename = new_filename.into_vec();
if let Some(copy) = copy_map.get(filename) { if let Some(copy) = copy_map.get(filename) {
...@@ -152,8 +148,6 @@ ...@@ -152,8 +148,6 @@
return Err(DirstatePackError::BadSize(expected_size, packed.len())); return Err(DirstatePackError::BadSize(expected_size, packed.len()));
} }
state_map.extend(new_state_map);
Ok(packed) Ok(packed)
} }
/// `now` is the duration in seconds since the Unix epoch /// `now` is the duration in seconds since the Unix epoch
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment