зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #2432 - Remove OptNewVector and use Vec instead (from SimonSapin:remove-optnewvector); r=larsbergstrom
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. r? @larsbergstrom Source-Repo: https://github.com/servo/servo Source-Revision: 309c9db2ac313cb78760615e893b2723a380eace
This commit is contained in:
Родитель
96c47a6ba2
Коммит
37ce7ff4c6
|
@ -107,10 +107,8 @@ impl ConstructionItem {
|
||||||
fn destroy(&mut self) {
|
fn destroy(&mut self) {
|
||||||
match *self {
|
match *self {
|
||||||
InlineBoxesConstructionItem(ref mut result) => {
|
InlineBoxesConstructionItem(ref mut result) => {
|
||||||
for splits in result.splits.mut_iter() {
|
for split in result.splits.mut_iter() {
|
||||||
for split in splits.mut_iter() {
|
split.destroy()
|
||||||
split.destroy()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WhitespaceConstructionItem(..) => {}
|
WhitespaceConstructionItem(..) => {}
|
||||||
|
@ -122,9 +120,7 @@ impl ConstructionItem {
|
||||||
/// Represents inline boxes and {ib} splits that are bubbling up from an inline.
|
/// Represents inline boxes and {ib} splits that are bubbling up from an inline.
|
||||||
pub struct InlineBoxesConstructionResult {
|
pub struct InlineBoxesConstructionResult {
|
||||||
/// Any {ib} splits that we're bubbling up.
|
/// Any {ib} splits that we're bubbling up.
|
||||||
///
|
pub splits: Vec<InlineBlockSplit>,
|
||||||
/// TODO(pcwalton): Small vector optimization.
|
|
||||||
pub splits: Option<Vec<InlineBlockSplit>>,
|
|
||||||
|
|
||||||
/// Any boxes that succeed the {ib} splits.
|
/// Any boxes that succeed the {ib} splits.
|
||||||
pub boxes: InlineBoxes,
|
pub boxes: InlineBoxes,
|
||||||
|
@ -216,58 +212,6 @@ enum WhitespaceStrippingMode {
|
||||||
StripWhitespaceFromEnd,
|
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.
|
/// An object that knows how to create flows.
|
||||||
pub struct FlowConstructor<'a> {
|
pub struct FlowConstructor<'a> {
|
||||||
/// The layout context.
|
/// The layout context.
|
||||||
|
@ -449,51 +393,46 @@ impl<'a> FlowConstructor<'a> {
|
||||||
}
|
}
|
||||||
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
|
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
|
||||||
InlineBoxesConstructionResult {
|
InlineBoxesConstructionResult {
|
||||||
splits: opt_splits,
|
splits: splits,
|
||||||
boxes: successor_boxes,
|
boxes: successor_boxes,
|
||||||
abs_descendants: kid_abs_descendants,
|
abs_descendants: kid_abs_descendants,
|
||||||
})) => {
|
})) => {
|
||||||
// Add any {ib} splits.
|
// Add any {ib} splits.
|
||||||
match opt_splits {
|
for split in splits.move_iter() {
|
||||||
None => {}
|
// Pull apart the {ib} split object and push its predecessor boxes
|
||||||
Some(splits) => {
|
// onto the list.
|
||||||
for split in splits.move_iter() {
|
let InlineBlockSplit {
|
||||||
// Pull apart the {ib} split object and push its predecessor boxes
|
predecessors: predecessors,
|
||||||
// onto the list.
|
flow: kid_flow
|
||||||
let InlineBlockSplit {
|
} = split;
|
||||||
predecessors: predecessors,
|
inline_box_accumulator.boxes.push_all(predecessors);
|
||||||
flow: kid_flow
|
|
||||||
} = split;
|
|
||||||
inline_box_accumulator.boxes.push_all(predecessors);
|
|
||||||
|
|
||||||
// If this is the first box in flow, then strip ignorable
|
// If this is the first box in flow, then strip ignorable
|
||||||
// whitespace per CSS 2.1 § 9.2.1.1.
|
// whitespace per CSS 2.1 § 9.2.1.1.
|
||||||
let whitespace_stripping = if *first_box {
|
let whitespace_stripping = if *first_box {
|
||||||
*first_box = false;
|
*first_box = false;
|
||||||
StripWhitespaceFromStart
|
StripWhitespaceFromStart
|
||||||
} else {
|
} else {
|
||||||
NoWhitespaceStripping
|
NoWhitespaceStripping
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flush any inline boxes that we were gathering up.
|
// Flush any inline boxes that we were gathering up.
|
||||||
debug!("flushing {} inline box(es) to flow A",
|
debug!("flushing {} inline box(es) to flow A",
|
||||||
inline_box_accumulator.boxes.len());
|
inline_box_accumulator.boxes.len());
|
||||||
self.flush_inline_boxes_to_flow_or_list(
|
self.flush_inline_boxes_to_flow_or_list(
|
||||||
mem::replace(inline_box_accumulator,
|
mem::replace(inline_box_accumulator,
|
||||||
InlineBoxAccumulator::new()),
|
InlineBoxAccumulator::new()),
|
||||||
flow,
|
flow,
|
||||||
consecutive_siblings,
|
consecutive_siblings,
|
||||||
whitespace_stripping,
|
whitespace_stripping,
|
||||||
node);
|
node);
|
||||||
|
|
||||||
// Push the flow generated by the {ib} split onto our list of
|
// Push the flow generated by the {ib} split onto our list of
|
||||||
// flows.
|
// flows.
|
||||||
if flow.need_anonymous_flow(kid_flow) {
|
if flow.need_anonymous_flow(kid_flow) {
|
||||||
consecutive_siblings.push(kid_flow)
|
consecutive_siblings.push(kid_flow)
|
||||||
} else {
|
} else {
|
||||||
flow.add_new_child(kid_flow)
|
flow.add_new_child(kid_flow)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +533,7 @@ impl<'a> FlowConstructor<'a> {
|
||||||
/// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace.
|
/// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace.
|
||||||
fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode)
|
fn build_boxes_for_nonreplaced_inline_content(&mut self, node: &ThreadSafeLayoutNode)
|
||||||
-> ConstructionResult {
|
-> 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 box_accumulator = InlineBoxAccumulator::from_inline_node(node);
|
||||||
let mut abs_descendants = Descendants::new();
|
let mut abs_descendants = Descendants::new();
|
||||||
|
|
||||||
|
@ -619,32 +558,27 @@ impl<'a> FlowConstructor<'a> {
|
||||||
}
|
}
|
||||||
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
|
ConstructionItemConstructionResult(InlineBoxesConstructionItem(
|
||||||
InlineBoxesConstructionResult {
|
InlineBoxesConstructionResult {
|
||||||
splits: opt_splits,
|
splits: splits,
|
||||||
boxes: successors,
|
boxes: successors,
|
||||||
abs_descendants: kid_abs_descendants,
|
abs_descendants: kid_abs_descendants,
|
||||||
})) => {
|
})) => {
|
||||||
|
|
||||||
// Bubble up {ib} splits.
|
// Bubble up {ib} splits.
|
||||||
match opt_splits {
|
for split in splits.move_iter() {
|
||||||
None => {}
|
let InlineBlockSplit {
|
||||||
Some(splits) => {
|
predecessors: predecessors,
|
||||||
for split in splits.move_iter() {
|
flow: kid_flow
|
||||||
let InlineBlockSplit {
|
} = split;
|
||||||
predecessors: predecessors,
|
box_accumulator.boxes.push_all(predecessors);
|
||||||
flow: kid_flow
|
|
||||||
} = split;
|
|
||||||
box_accumulator.boxes.push_all(predecessors);
|
|
||||||
|
|
||||||
let split = InlineBlockSplit {
|
let split = InlineBlockSplit {
|
||||||
predecessors:
|
predecessors:
|
||||||
mem::replace(&mut box_accumulator,
|
mem::replace(&mut box_accumulator,
|
||||||
InlineBoxAccumulator::from_inline_node(node))
|
InlineBoxAccumulator::from_inline_node(node))
|
||||||
.finish(),
|
.finish(),
|
||||||
flow: kid_flow,
|
flow: kid_flow,
|
||||||
};
|
};
|
||||||
opt_inline_block_splits.push(split)
|
opt_inline_block_splits.push(split)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push residual boxes.
|
// Push residual boxes.
|
||||||
|
@ -704,7 +638,7 @@ impl<'a> FlowConstructor<'a> {
|
||||||
boxes.push(Box::new(self, node), node.style().clone());
|
boxes.push(Box::new(self, node), node.style().clone());
|
||||||
|
|
||||||
let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult {
|
let construction_item = InlineBoxesConstructionItem(InlineBoxesConstructionResult {
|
||||||
splits: None,
|
splits: Vec::new(),
|
||||||
boxes: boxes,
|
boxes: boxes,
|
||||||
abs_descendants: Descendants::new(),
|
abs_descendants: Descendants::new(),
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче