##// END OF EJS Templates
rust-parsers: use in-place mutation instead of allocating a new `Vec`...
Raphaël Gomès -
r46223:1efbc787 default
parent child Browse files
Show More
@@ -107,12 +107,11 b' pub fn pack_dirstate('
107 let expected_size = expected_size + PARENT_SIZE * 2;
107 let expected_size = expected_size + PARENT_SIZE * 2;
108
108
109 let mut packed = Vec::with_capacity(expected_size);
109 let mut packed = Vec::with_capacity(expected_size);
110 let mut new_state_map = vec![];
111
110
112 packed.extend(&parents.p1);
111 packed.extend(&parents.p1);
113 packed.extend(&parents.p2);
112 packed.extend(&parents.p2);
114
113
115 for (filename, entry) in state_map.iter() {
114 for (filename, entry) in state_map.iter_mut() {
116 let new_filename = filename.to_owned();
115 let new_filename = filename.to_owned();
117 let mut new_mtime: i32 = entry.mtime;
116 let mut new_mtime: i32 = entry.mtime;
118 if entry.state == EntryState::Normal && entry.mtime == now {
117 if entry.state == EntryState::Normal && entry.mtime == now {
@@ -126,13 +125,10 b' pub fn pack_dirstate('
126 // contents of the file if the size is the same. This prevents
125 // contents of the file if the size is the same. This prevents
127 // mistakenly treating such files as clean.
126 // mistakenly treating such files as clean.
128 new_mtime = -1;
127 new_mtime = -1;
129 new_state_map.push((
128 *entry = DirstateEntry {
130 filename.to_owned(),
129 mtime: new_mtime,
131 DirstateEntry {
130 ..*entry
132 mtime: new_mtime,
131 };
133 ..*entry
134 },
135 ));
136 }
132 }
137 let mut new_filename = new_filename.into_vec();
133 let mut new_filename = new_filename.into_vec();
138 if let Some(copy) = copy_map.get(filename) {
134 if let Some(copy) = copy_map.get(filename) {
@@ -152,8 +148,6 b' pub fn pack_dirstate('
152 return Err(DirstatePackError::BadSize(expected_size, packed.len()));
148 return Err(DirstatePackError::BadSize(expected_size, packed.len()));
153 }
149 }
154
150
155 state_map.extend(new_state_map);
156
157 Ok(packed)
151 Ok(packed)
158 }
152 }
159 /// `now` is the duration in seconds since the Unix epoch
153 /// `now` is the duration in seconds since the Unix epoch
General Comments 0
You need to be logged in to leave comments. Login now