From 62bbe1f555a10a83473c6527ed4fe804f0fa864a Mon Sep 17 00:00:00 2001 From: Matt Murphy Date: Tue, 22 Apr 2014 18:14:33 -0500 Subject: [PATCH] ~[] to Vec in main/layout/construct.rs and associated files --- src/components/main/layout/construct.rs | 56 ++++++++++++++++++++++++- src/components/main/layout/flow.rs | 1 - 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 40d976f97ab..6bf95bd85f9 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -125,7 +125,7 @@ pub struct InlineBoxesConstructionResult { /// Any {ib} splits that we're bubbling up. /// /// TODO(pcwalton): Small vector optimization. - pub splits: Option<~[InlineBlockSplit]>, + pub splits: Option>, /// Any boxes that succeed the {ib} splits. pub boxes: InlineBoxes, @@ -280,6 +280,58 @@ enum WhitespaceStrippingMode { StripWhitespaceFromEnd, } +/// Methods on optional vectors. +/// +/// TODO: This is no longer necessary. This should be removed. +pub trait OptNewVector { + /// Turns this optional vector into an owned one. If the optional vector is `None`, then this + /// simply returns an empty owned vector. + fn to_vec(self) -> Vec; + + /// Pushes a value onto this vector. + fn push(&mut self, value: T); + + /// Pushes a vector onto this vector, consuming the original. + fn push_all_move(&mut self, values: Vec); + + /// Returns the length of this optional vector. + fn len(&self) -> uint; +} + +impl OptNewVector for Option> { + #[inline] + fn to_vec(self) -> Vec { + match self { + None => Vec::new(), + Some(vector) => vector, + } + } + + #[inline] + fn push(&mut self, value: T) { + match *self { + None => *self = Some(vec!(value)), + Some(ref mut vector) => vector.push(value), + } + } + + #[inline] + fn push_all_move(&mut self, values: Vec) { + match *self { + None => *self = Some(values), + Some(ref mut vector) => vector.push_all_move(values), + } + } + + #[inline] + fn len(&self) -> uint { + match *self { + None => 0, + Some(ref vector) => vector.len(), + } + } +} + /// An object that knows how to create flows. pub struct FlowConstructor<'a> { /// The layout context. @@ -606,7 +658,7 @@ impl<'a> FlowConstructor<'a> { /// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace. fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { - let mut opt_inline_block_splits = None; + let mut opt_inline_block_splits: Option> = None; let mut box_accumulator = InlineBoxAccumulator::from_inline_node(node); let mut abs_descendants = Descendants::new(); diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index f734fe24058..d16fb5622a6 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -28,7 +28,6 @@ use css::node_style::StyledNode; use layout::block::BlockFlow; use layout::box_::{Box, TableRowBox, TableCellBox}; -use layout::construct::OptVector; use layout::context::LayoutContext; use layout::floats::Floats; use layout::flow_list::{FlowList, Link, Rawlink, FlowListIterator, MutFlowListIterator};