Remove OptNewVector and use Vec instead.

Before we had Vec<T>, Option<~[T]> was used as an optimization of ~[T]
to avoid allocating for empty vectors when that was the common case.
Vec<T> itself does this optimization, so there is no need for this anymore.
This commit is contained in:
Simon Sapin 2014-05-14 15:47:57 +01:00
parent 2168956a59
commit d3a53296cd

View file

@ -107,12 +107,10 @@ impl ConstructionItem {
fn destroy(&mut self) {
match *self {
InlineBoxesConstructionItem(ref mut result) => {
for splits in result.splits.mut_iter() {
for split in splits.mut_iter() {
for split in result.splits.mut_iter() {
split.destroy()
}
}
}
WhitespaceConstructionItem(..) => {}
TableColumnBoxConstructionItem(_) => {}
}
@ -122,9 +120,7 @@ impl ConstructionItem {
/// Represents inline boxes and {ib} splits that are bubbling up from an inline.
pub struct InlineBoxesConstructionResult {
/// Any {ib} splits that we're bubbling up.
///
/// TODO(pcwalton): Small vector optimization.
pub splits: Option<Vec<InlineBlockSplit>>,
pub splits: Vec<InlineBlockSplit>,
/// Any boxes that succeed the {ib} splits.
pub boxes: InlineBoxes,
@ -216,58 +212,6 @@ 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.
@ -449,14 +393,11 @@ impl<'a> FlowConstructor<'a> {
}
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
InlineBoxesConstructionResult {
splits: opt_splits,
splits: splits,
boxes: successor_boxes,
abs_descendants: kid_abs_descendants,
})) => {
// Add any {ib} splits.
match opt_splits {
None => {}
Some(splits) => {
for split in splits.move_iter() {
// Pull apart the {ib} split object and push its predecessor boxes
// onto the list.
@ -494,8 +435,6 @@ impl<'a> FlowConstructor<'a> {
flow.add_new_child(kid_flow)
}
}
}
}
// Add the boxes to the list we're maintaining.
inline_box_accumulator.boxes.push_all(successor_boxes);
@ -594,7 +533,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: Option<Vec<InlineBlockSplit>> = None;
let mut opt_inline_block_splits: Vec<InlineBlockSplit> = Vec::new();
let mut box_accumulator = InlineBoxAccumulator::from_inline_node(node);
let mut abs_descendants = Descendants::new();
@ -619,15 +558,12 @@ impl<'a> FlowConstructor<'a> {
}
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
InlineBoxesConstructionResult {
splits: opt_splits,
splits: splits,
boxes: successors,
abs_descendants: kid_abs_descendants,
})) => {
// Bubble up {ib} splits.
match opt_splits {
None => {}
Some(splits) => {
for split in splits.move_iter() {
let InlineBlockSplit {
predecessors: predecessors,
@ -644,8 +580,6 @@ impl<'a> FlowConstructor<'a> {
};
opt_inline_block_splits.push(split)
}
}
}
// Push residual boxes.
box_accumulator.boxes.push_all(successors);
@ -704,7 +638,7 @@ impl<'a> FlowConstructor<'a> {
boxes.push(Box::new(self, node), node.style().clone());
let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult {
splits: None,
splits: Vec::new(),
boxes: boxes,
abs_descendants: Descendants::new(),
});