Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use std::mem::take instead of defining it
  • Loading branch information
SimonSapin committed Nov 26, 2019
1 parent b2b3ea9 commit 80eec48
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
5 changes: 2 additions & 3 deletions components/layout_2020/flow/construct.rs
Expand Up @@ -10,7 +10,6 @@ use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
use crate::formatting_contexts::IndependentFormattingContext;
use crate::positioned::AbsolutelyPositionedBox;
use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside};
use crate::take;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rayon_croissant::ParallelIteratorExt;
use servo_arc::Arc;
Expand Down Expand Up @@ -381,7 +380,7 @@ where
// The fragmented boxes before the block level element
// are obviously not the last fragment.
last_fragment: false,
children: take(&mut ongoing.children),
children: std::mem::take(&mut ongoing.children),
};
ongoing.first_fragment = false;
fragmented
Expand Down Expand Up @@ -516,7 +515,7 @@ where

let box_ = IntermediateBlockLevelBox::SameFormattingContextBlock {
style: anonymous_style.clone(),
contents: IntermediateBlockContainer::InlineFormattingContext(take(
contents: IntermediateBlockContainer::InlineFormattingContext(std::mem::take(
&mut self.ongoing_inline_formatting_context,
)),
};
Expand Down
6 changes: 3 additions & 3 deletions components/layout_2020/flow/inline.rs
Expand Up @@ -12,7 +12,7 @@ use crate::geom::flow_relative::{Rect, Sides, Vec2};
use crate::positioned::{AbsolutelyPositionedBox, AbsolutelyPositionedFragment};
use crate::replaced::ReplacedContent;
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
use crate::{relative_adjustement, take, ContainingBlock};
use crate::{relative_adjustement, ContainingBlock};
use servo_arc::Arc;
use style::properties::ComputedValues;
use style::values::computed::Length;
Expand Down Expand Up @@ -185,7 +185,7 @@ impl LinesBoxes {
};
self.next_line_block_position += size.block;
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 },
mode: containing_block.mode,
}))
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'box_tree> PartialInlineBoxFragment<'box_tree> {
) {
let mut fragment = BoxFragment {
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 {
size: Vec2 {
inline: *inline_position - self.start_corner.inline,
Expand Down
9 changes: 0 additions & 9 deletions components/layout_2020/lib.rs
Expand Up @@ -81,12 +81,3 @@ fn relative_adjustement(
block: adjust(box_offsets.block_start, box_offsets.block_end),
}
}

// FIXME: use std::mem::take when it’s 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())
}

0 comments on commit 80eec48

Please sign in to comment.