Use std::mem::take instead of defining it

This commit is contained in:
Simon Sapin 2019-11-26 11:24:53 +01:00
parent b2b3ea992c
commit 80eec48d37
3 changed files with 5 additions and 15 deletions

View file

@ -10,7 +10,6 @@ use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
use crate::formatting_contexts::IndependentFormattingContext; use crate::formatting_contexts::IndependentFormattingContext;
use crate::positioned::AbsolutelyPositionedBox; use crate::positioned::AbsolutelyPositionedBox;
use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside}; use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside};
use crate::take;
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rayon_croissant::ParallelIteratorExt; use rayon_croissant::ParallelIteratorExt;
use servo_arc::Arc; use servo_arc::Arc;
@ -381,7 +380,7 @@ where
// The fragmented boxes before the block level element // The fragmented boxes before the block level element
// are obviously not the last fragment. // are obviously not the last fragment.
last_fragment: false, last_fragment: false,
children: take(&mut ongoing.children), children: std::mem::take(&mut ongoing.children),
}; };
ongoing.first_fragment = false; ongoing.first_fragment = false;
fragmented fragmented
@ -516,7 +515,7 @@ where
let box_ = IntermediateBlockLevelBox::SameFormattingContextBlock { let box_ = IntermediateBlockLevelBox::SameFormattingContextBlock {
style: anonymous_style.clone(), style: anonymous_style.clone(),
contents: IntermediateBlockContainer::InlineFormattingContext(take( contents: IntermediateBlockContainer::InlineFormattingContext(std::mem::take(
&mut self.ongoing_inline_formatting_context, &mut self.ongoing_inline_formatting_context,
)), )),
}; };

View file

@ -12,7 +12,7 @@ use crate::geom::flow_relative::{Rect, Sides, Vec2};
use crate::positioned::{AbsolutelyPositionedBox, AbsolutelyPositionedFragment}; use crate::positioned::{AbsolutelyPositionedBox, AbsolutelyPositionedFragment};
use crate::replaced::ReplacedContent; use crate::replaced::ReplacedContent;
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside}; use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
use crate::{relative_adjustement, take, ContainingBlock}; use crate::{relative_adjustement, ContainingBlock};
use servo_arc::Arc; use servo_arc::Arc;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::Length; use style::values::computed::Length;
@ -185,7 +185,7 @@ impl LinesBoxes {
}; };
self.next_line_block_position += size.block; self.next_line_block_position += size.block;
self.boxes.push(Fragment::Anonymous(AnonymousFragment { self.boxes.push(Fragment::Anonymous(AnonymousFragment {
children: take(&mut top_nesting_level.fragments_so_far), children: std::mem::take(&mut top_nesting_level.fragments_so_far),
rect: Rect { start_corner, size }, rect: Rect { start_corner, size },
mode: containing_block.mode, mode: containing_block.mode,
})) }))
@ -250,7 +250,7 @@ impl<'box_tree> PartialInlineBoxFragment<'box_tree> {
) { ) {
let mut fragment = BoxFragment { let mut fragment = BoxFragment {
style: self.style.clone(), style: self.style.clone(),
children: take(&mut nesting_level.fragments_so_far), children: std::mem::take(&mut nesting_level.fragments_so_far),
content_rect: Rect { content_rect: Rect {
size: Vec2 { size: Vec2 {
inline: *inline_position - self.start_corner.inline, inline: *inline_position - self.start_corner.inline,

View file

@ -81,12 +81,3 @@ fn relative_adjustement(
block: adjust(box_offsets.block_start, box_offsets.block_end), block: adjust(box_offsets.block_start, box_offsets.block_end),
} }
} }
// FIXME: use std::mem::take when its stable.
// https://github.com/rust-lang/rust/issues/61129
fn take<T>(x: &mut T) -> T
where
T: Default,
{
std::mem::replace(x, Default::default())
}