Replace replace(..., None) with take()

This is strictly for simplicity, since Option::take() is imlemented with replace().
This commit is contained in:
Jay Kickliter 2018-09-14 13:13:36 -07:00 committed by Greg Fitzgerald
parent 3ca80c676c
commit fd51599fa8
3 changed files with 4 additions and 5 deletions

View File

@ -8,7 +8,6 @@ use log::Level;
use packet::BlobRecycler;
use result::{Error, Result};
use service::Service;
use std::mem;
use std::net::UdpSocket;
use std::sync::atomic::AtomicUsize;
use std::sync::mpsc::RecvTimeoutError;
@ -60,7 +59,7 @@ fn broadcast(
for b in &blobs {
let ix = b.read().unwrap().get_index().expect("blob index");
let pos = (ix % WINDOW_SIZE) as usize;
if let Some(x) = mem::replace(&mut win[pos].data, None) {
if let Some(x) = win[pos].data.take() {
trace!(
"{} popped {} at {}",
id,
@ -69,7 +68,7 @@ fn broadcast(
);
recycler.recycle(x, "broadcast-data");
}
if let Some(x) = mem::replace(&mut win[pos].coding, None) {
if let Some(x) = win[pos].coding.take() {
trace!(
"{} popped {} at {}",
id,

View File

@ -363,7 +363,7 @@ fn is_missing(
recycler: &BlobRecycler,
c_or_d: &str,
) -> bool {
if let Some(blob) = mem::replace(window_slot, None) {
if let Some(blob) = window_slot.take() {
let blob_idx = blob.read().unwrap().get_index().unwrap();
if blob_idx == idx {
trace!("recover {}: idx: {} good {}", id, idx, c_or_d);

View File

@ -34,7 +34,7 @@ impl WindowSlot {
}
fn clear_data(&mut self, recycler: &BlobRecycler) {
if let Some(blob) = mem::replace(&mut self.data, None) {
if let Some(blob) = self.data.take() {
recycler.recycle(blob, "WindowSlot::clear_data");
}
}