diff options
author | Matt Murphy <matthew.john.murphy@gmail.com> | 2014-04-22 18:14:33 -0500 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-05-04 23:16:16 +0200 |
commit | 62bbe1f555a10a83473c6527ed4fe804f0fa864a (patch) | |
tree | 90e433d8caabe9fdd493b5fd25726bf2e0248ace /src/components/main/layout/construct.rs | |
parent | 8da47b6a32e15bdfc928cfd97471639267a46c04 (diff) | |
download | servo-62bbe1f555a10a83473c6527ed4fe804f0fa864a.tar.gz servo-62bbe1f555a10a83473c6527ed4fe804f0fa864a.zip |
~[] to Vec in main/layout/construct.rs and associated files
Diffstat (limited to 'src/components/main/layout/construct.rs')
-rw-r--r-- | src/components/main/layout/construct.rs | 56 |
1 files changed, 54 insertions, 2 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<Vec<InlineBlockSplit>>, /// 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<T> { + /// 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<T>; + + /// 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<T>); + + /// Returns the length of this optional vector. + fn len(&self) -> uint; +} + +impl<T> OptNewVector<T> for Option<Vec<T>> { + #[inline] + fn to_vec(self) -> Vec<T> { + 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<T>) { + 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<Vec<InlineBlockSplit>> = None; let mut box_accumulator = InlineBoxAccumulator::from_inline_node(node); let mut abs_descendants = Descendants::new(); |