Skip to content

Commit

Permalink
clippy: Fix mem_replace_with_default warnings (#31921)
Browse files Browse the repository at this point in the history
  • Loading branch information
oluwatobiss committed Mar 28, 2024
1 parent 7100465 commit 66ad795
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 22 deletions.
11 changes: 3 additions & 8 deletions components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,14 +816,10 @@ impl LayoutThread {
build_state.root_stacking_context.overflow = origin;

// We will not use build_state.iframe_sizes again, so it's safe to move it.
let iframe_sizes =
std::mem::replace(&mut build_state.iframe_sizes, FnvHashMap::default());
let iframe_sizes = std::mem::take(&mut build_state.iframe_sizes);
self.update_iframe_sizes(iframe_sizes);

rw_data.indexable_text = std::mem::replace(
&mut build_state.indexable_text,
IndexableText::default(),
);
rw_data.indexable_text = std::mem::take(&mut build_state.indexable_text);
rw_data.display_list = Some(build_state.to_display_list());
}
}
Expand Down Expand Up @@ -1186,8 +1182,7 @@ impl LayoutThread {
reflow_result: &mut ReflowComplete,
shared_lock: &SharedRwLock,
) {
reflow_result.pending_images =
std::mem::replace(&mut *context.pending_images.lock().unwrap(), vec![]);
reflow_result.pending_images = std::mem::take(&mut *context.pending_images.lock().unwrap());

let mut root_flow = match self.root_flow.borrow().clone() {
Some(root_flow) => root_flow,
Expand Down
3 changes: 1 addition & 2 deletions components/layout_thread_2020/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ impl LayoutThread {
reflow_result: &mut ReflowComplete,
shared_lock: &SharedRwLock,
) {
reflow_result.pending_images =
std::mem::replace(&mut *context.pending_images.lock().unwrap(), vec![]);
reflow_result.pending_images = std::mem::take(&mut *context.pending_images.lock().unwrap());

match *reflow_goal {
ReflowGoal::LayoutQuery(ref querymsg, _) => match querymsg {
Expand Down
2 changes: 1 addition & 1 deletion components/script/animations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl Animations {
pub(crate) fn send_pending_events(&self, window: &Window) {
// Take all of the events here, in case sending one of these events
// triggers adding new events by forcing a layout.
let events = std::mem::replace(&mut *self.pending_events.borrow_mut(), Vec::new());
let events = std::mem::take(&mut *self.pending_events.borrow_mut());
if events.is_empty() {
return;
}
Expand Down
5 changes: 1 addition & 4 deletions components/script/dom/canvasrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ impl CanvasRenderingContext2D {
}

pub fn take_missing_image_urls(&self) -> Vec<ServoUrl> {
mem::replace(
&mut self.canvas_state.get_missing_image_urls().borrow_mut(),
vec![],
)
std::mem::take(&mut self.canvas_state.get_missing_image_urls().borrow_mut())
}

pub fn get_canvas_id(&self) -> CanvasId {
Expand Down
3 changes: 1 addition & 2 deletions components/script/dom/htmlmediaelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,7 @@ impl HTMLMediaElement {
/// `fulfill_in_flight_play_promises`, to actually fulfill the promises
/// which were taken and moved to the in-flight queue.
fn take_pending_play_promises(&self, result: ErrorResult) {
let pending_play_promises =
mem::replace(&mut *self.pending_play_promises.borrow_mut(), vec![]);
let pending_play_promises = std::mem::take(&mut *self.pending_play_promises.borrow_mut());
self.in_flight_play_promises_queue
.borrow_mut()
.push_back((pending_play_promises.into(), result));
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlscriptelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ unsafe extern "C" fn off_thread_compilation_callback(
let final_url = context.final_url.clone();
let script_element = context.script_element.clone();
let script_kind = context.script_kind;
let script = replace(&mut context.script_text, String::new());
let script = std::mem::take(&mut context.script_text);
let fetch_options = context.fetch_options.clone();

// Continue with <https://html.spec.whatwg.org/multipage/#fetch-a-classic-script>
Expand Down
5 changes: 1 addition & 4 deletions components/script/dom/servoparser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,10 +1401,7 @@ impl NetworkDecoder {

fn decode(&mut self, chunk: Vec<u8>) -> StrTendril {
self.decoder.process(ByteTendril::from(&*chunk));
mem::replace(
&mut self.decoder.inner_sink_mut().output,
Default::default(),
)
std::mem::take(&mut self.decoder.inner_sink_mut().output)
}

fn finish(self) -> StrTendril {
Expand Down

0 comments on commit 66ad795

Please sign in to comment.