Skip to content

Commit

Permalink
Auto merge of #8314 - cuviper:mem-take, r=Eh2406
Browse files Browse the repository at this point in the history
Use mem::take to replace with Default values
  • Loading branch information
bors committed Jun 3, 2020
2 parents ebe57ad + 6a6fa36 commit 5f63be6
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ fn calc_deps_of_std(
deps_of_roots(roots, &mut state)?;
}
state.is_std = false;
Ok(Some(std::mem::replace(
&mut state.unit_dependencies,
HashMap::new(),
)))
Ok(Some(std::mem::take(&mut state.unit_dependencies)))
}

/// Add the standard library units to the `unit_dependencies`.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
.pending
.remove(&token)
.expect("got a token for a non-in-progress transfer");
let data = mem::replace(&mut *dl.data.borrow_mut(), Vec::new());
let data = mem::take(&mut *dl.data.borrow_mut());
let mut handle = self.set.multi.remove(handle)?;
self.pending_ids.remove(&dl.id);

Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl Summary {
{
{
let slot = &mut Rc::make_mut(&mut self.inner).dependencies;
let deps = mem::replace(slot, Vec::new());
*slot = deps.into_iter().map(f).collect();
*slot = mem::take(slot).into_iter().map(f).collect();
}
self
}
Expand Down
6 changes: 2 additions & 4 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,12 +1452,10 @@ impl ConfigValue {
fn merge(&mut self, from: ConfigValue, force: bool) -> CargoResult<()> {
match (self, from) {
(&mut CV::List(ref mut old, _), CV::List(ref mut new, _)) => {
let new = mem::replace(new, Vec::new());
old.extend(new.into_iter());
old.extend(mem::take(new).into_iter());
}
(&mut CV::Table(ref mut old, _), CV::Table(ref mut new, _)) => {
let new = mem::replace(new, HashMap::new());
for (key, value) in new {
for (key, value) in mem::take(new) {
match old.entry(key.clone()) {
Occupied(mut entry) => {
let new_def = value.definition().clone();
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/util/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ impl Drop for Profiler {
let duration = start.elapsed();
let duration_ms = duration.as_secs() * 1000 + u64::from(duration.subsec_millis());

let msg = (
stack_len,
duration_ms,
mem::replace(&mut self.desc, String::new()),
);
let msg = (stack_len, duration_ms, mem::take(&mut self.desc));
MESSAGES.with(|msgs| msgs.borrow_mut().push(msg));

if stack_len == 0 {
Expand Down

0 comments on commit 5f63be6

Please sign in to comment.