Skip to content

Commit

Permalink
Replace most of the SmallVec0 usages with std::vec::Vec
Browse files Browse the repository at this point in the history
We can't replace the ones in the `style` crate because some functions expect generic `SmallVec`s.
  • Loading branch information
brendanzab committed May 5, 2014
1 parent b24cc80 commit 42bf406
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
5 changes: 2 additions & 3 deletions src/components/gfx/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use libc::uintptr_t;
use servo_net::image::base::Image;
use servo_util::geometry::Au;
use servo_util::range::Range;
use servo_util::smallvec::{SmallVec, SmallVec0};
use std::mem;
use std::slice::Items;
use style::computed_values::border_style;
Expand Down Expand Up @@ -90,7 +89,7 @@ struct StackingContext {
///
/// TODO(pcwalton): `z-index` should be the actual CSS property value in order to handle
/// `auto`, not just an integer.
pub positioned_descendants: SmallVec0<(i32, DisplayList)>,
pub positioned_descendants: Vec<(i32, DisplayList)>,
}

impl StackingContext {
Expand All @@ -105,7 +104,7 @@ impl StackingContext {
block_backgrounds_and_borders: DisplayList::new(),
floats: DisplayList::new(),
content: DisplayList::new(),
positioned_descendants: SmallVec0::new(),
positioned_descendants: Vec::new(),
};

for item in list.move_iter() {
Expand Down
7 changes: 4 additions & 3 deletions src/components/main/layout/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use gfx::render_task::RenderLayer;
use servo_msg::compositor_msg::{FixedPosition, LayerId, Scrollable};
use servo_util::geometry::Au;
use servo_util::geometry;
use servo_util::smallvec::{SmallVec, SmallVec0};
use std::mem;
use std::num::Zero;
use style::computed_values::{LPA_Auto, LPA_Length, LPA_Percentage, LPN_Length, LPN_None};
Expand Down Expand Up @@ -733,7 +732,7 @@ impl BlockFlow {
/// In the case of absolute flow kids, they have their hypothetical box
/// position already set.
fn collect_static_y_offsets_from_kids(&mut self) {
let mut abs_descendant_y_offsets = SmallVec0::new();
let mut abs_descendant_y_offsets = Vec::new();
for kid in self.base.child_iter() {
let mut gives_abs_offsets = true;
if kid.is_block_like() {
Expand All @@ -753,8 +752,10 @@ impl BlockFlow {

if gives_abs_offsets {
let kid_base = flow::mut_base(kid);
// Avoid copying the offset vector.
let offsets = mem::replace(&mut kid_base.abs_descendants.static_y_offsets, Vec::new());
// Consume all the static y-offsets bubbled up by kid.
for y_offset in kid_base.abs_descendants.static_y_offsets.move_iter() {
for y_offset in offsets.move_iter() {
// The offsets are wrt the kid flow box. Translate them to current flow.
abs_descendant_y_offsets.push(y_offset + kid_base.position.origin.y);
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/main/layout/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use script::dom::node::{TextNodeTypeId};
use script::dom::text::Text;
use servo_util::namespace;
use servo_util::range::Range;
use servo_util::smallvec::{SmallVec, SmallVec0};
use servo_util::str::is_whitespace;
use servo_util::url::{is_image_data, parse_url};
use std::mem;
Expand Down Expand Up @@ -1226,7 +1225,7 @@ fn strip_ignorable_whitespace_from_start(boxes: &mut InlineBoxes) {

// FIXME(#2264, pcwalton): This is slow because vector shift is broken. :(
let mut found_nonwhitespace = false;
let mut new_boxes = SmallVec0::new();
let mut new_boxes = Vec::new();
for fragment in old_boxes.iter() {
if !found_nonwhitespace && fragment.is_whitespace_only() {
debug!("stripping ignorable whitespace from start");
Expand Down
9 changes: 4 additions & 5 deletions src/components/main/layout/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use gfx::display_list::DisplayList;
use gfx::render_task::RenderLayer;
use servo_msg::compositor_msg::LayerId;
use servo_util::geometry::Au;
use servo_util::smallvec::{SmallVec, SmallVec0};
use std::cast;
use std::iter::Zip;
use std::num::Zero;
Expand Down Expand Up @@ -558,16 +557,16 @@ impl FlowFlags {
/// FIXME: This should use @pcwalton's reference counting scheme (Coming Soon).
pub struct Descendants {
/// Links to every Descendant.
pub descendant_links: SmallVec0<Rawlink>,
pub descendant_links: Vec<Rawlink>,
/// Static y offsets of all descendants from the start of this flow box.
pub static_y_offsets: SmallVec0<Au>,
pub static_y_offsets: Vec<Au>,
}

impl Descendants {
pub fn new() -> Descendants {
Descendants {
descendant_links: SmallVec0::new(),
static_y_offsets: SmallVec0::new(),
descendant_links: Vec::new(),
static_y_offsets: Vec::new(),
}
}

Expand Down
33 changes: 16 additions & 17 deletions src/components/main/layout/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use gfx::font_context::FontContext;
use servo_util::geometry::Au;
use servo_util::geometry;
use servo_util::range::Range;
use servo_util::smallvec::{SmallVec, SmallVec0};
use std::iter::Enumerate;
use std::mem;
use std::slice::{Items, MutItems};
Expand Down Expand Up @@ -63,25 +62,25 @@ pub struct LineBox {

struct LineboxScanner {
pub floats: Floats,
pub new_boxes: SmallVec0<Box>,
pub new_boxes: Vec<Box>,
pub work_list: RingBuf<Box>,
pub pending_line: LineBox,
pub lines: SmallVec0<LineBox>,
pub lines: Vec<LineBox>,
pub cur_y: Au,
}

impl LineboxScanner {
pub fn new(float_ctx: Floats) -> LineboxScanner {
LineboxScanner {
floats: float_ctx,
new_boxes: SmallVec0::new(),
new_boxes: Vec::new(),
work_list: RingBuf::new(),
pending_line: LineBox {
range: Range::empty(),
bounds: Rect(Point2D(Au::new(0), Au::new(0)), Size2D(Au::new(0), Au::new(0))),
green_zone: Size2D(Au::new(0), Au::new(0))
},
lines: SmallVec0::new(),
lines: Vec::new(),
cur_y: Au::new(0)
}
}
Expand All @@ -92,8 +91,8 @@ impl LineboxScanner {

fn reset_scanner(&mut self) {
debug!("Resetting line box scanner's state for flow.");
self.lines = SmallVec0::new();
self.new_boxes = SmallVec0::new();
self.lines = Vec::new();
self.new_boxes = Vec::new();
self.cur_y = Au(0);
self.reset_linebox();
}
Expand Down Expand Up @@ -154,11 +153,11 @@ impl LineboxScanner {

map.fixup(old_boxes.as_slice(), self.new_boxes.as_slice());
flow.boxes = InlineBoxes {
boxes: mem::replace(&mut self.new_boxes, SmallVec0::new()),
boxes: mem::replace(&mut self.new_boxes, Vec::new()),
map: map,
};

flow.lines = mem::replace(&mut self.lines, SmallVec0::new());
flow.lines = mem::replace(&mut self.lines, Vec::new());
}

fn flush_current_line(&mut self) {
Expand Down Expand Up @@ -492,7 +491,7 @@ impl<'a> Iterator<(&'a mut Box, InlineFragmentContext<'a>)> for MutBoxIterator<'
/// Represents a list of inline boxes, including element ranges.
pub struct InlineBoxes {
/// The boxes themselves.
pub boxes: SmallVec0<Box>,
pub boxes: Vec<Box>,
/// Tracks the elements that made up the boxes above.
pub map: FragmentMap,
}
Expand All @@ -501,7 +500,7 @@ impl InlineBoxes {
/// Creates an empty set of inline boxes.
pub fn new() -> InlineBoxes {
InlineBoxes {
boxes: SmallVec0::new(),
boxes: Vec::new(),
map: FragmentMap::new(),
}
}
Expand Down Expand Up @@ -572,7 +571,7 @@ pub struct InlineFlow {
/// A vector of ranges into boxes that represents line positions. These ranges are disjoint and
/// are the result of inline layout. This also includes some metadata used for positioning
/// lines.
pub lines: SmallVec0<LineBox>,
pub lines: Vec<LineBox>,

/// The minimum height above the baseline for each line, as specified by the line height and
/// font style.
Expand All @@ -588,7 +587,7 @@ impl InlineFlow {
InlineFlow {
base: BaseFlow::new(node),
boxes: boxes,
lines: SmallVec0::new(),
lines: Vec::new(),
minimum_height_above_baseline: Au(0),
minimum_depth_below_baseline: Au(0),
}
Expand Down Expand Up @@ -1045,14 +1044,14 @@ impl<'a> Iterator<&'a FragmentRange> for RangeIterator<'a> {
/// Information that inline flows keep about nested elements. This is used to recover the DOM
/// structure from the flat box list when it's needed.
pub struct FragmentMap {
list: SmallVec0<FragmentRange>,
list: Vec<FragmentRange>,
}

impl FragmentMap {
/// Creates a new fragment map.
pub fn new() -> FragmentMap {
FragmentMap {
list: SmallVec0::new(),
list: Vec::new(),
}
}

Expand Down Expand Up @@ -1105,8 +1104,8 @@ impl FragmentMap {
/// needlessly has to clone boxes.
pub fn fixup(&mut self, old_fragments: &[Box], new_fragments: &[Box]) {
// TODO(pcwalton): Post Rust upgrade, use `with_capacity` here.
let mut old_list = mem::replace(&mut self.list, SmallVec0::new());
let mut worklist = SmallVec0::new(); // FIXME(#2269, pcwalton): was smallvec4
let mut old_list = mem::replace(&mut self.list, Vec::new());
let mut worklist = Vec::new(); // FIXME(#2269, pcwalton): was smallvec4
let mut old_list_iter = old_list.move_iter().peekable();
let mut new_fragments_iter = new_fragments.iter().enumerate().peekable();

Expand Down
5 changes: 2 additions & 3 deletions src/components/main/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use gfx::text::text_run::TextRun;
use gfx::text::util::{CompressWhitespaceNewline, transform_text, CompressNone};
use servo_util::geometry::Au;
use servo_util::range::Range;
use servo_util::smallvec::{SmallVec, SmallVec0};
use std::mem;
use style::ComputedValues;
use style::computed_values::{font_family, line_height, white_space};
Expand Down Expand Up @@ -54,7 +53,7 @@ impl TextRunScanner {
} = mem::replace(&mut flow.as_inline().boxes, InlineBoxes::new());

let mut last_whitespace = true;
let mut new_boxes = SmallVec0::new();
let mut new_boxes = Vec::new();
for box_i in range(0, old_boxes.len()) {
debug!("TextRunScanner: considering box: {:u}", box_i);
if box_i > 0 && !can_coalesce_text_nodes(old_boxes.as_slice(), box_i - 1, box_i) {
Expand Down Expand Up @@ -97,7 +96,7 @@ impl TextRunScanner {
pub fn flush_clump_to_list(&mut self,
font_context: &mut FontContext,
in_boxes: &[Box],
out_boxes: &mut SmallVec0<Box>,
out_boxes: &mut Vec<Box>,
last_whitespace: bool)
-> bool {
assert!(self.clump.length() > 0);
Expand Down

5 comments on commit 42bf406

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at brendanzab@42bf406

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/servo/smallvec = 42bf406 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/servo/smallvec = 42bf406 merged ok, testing candidate = b6c7856

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b6c7856

Please sign in to comment.