mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
auto merge of #2337 : bjz/servo/smallvec, r=pcwalton
We can't replace the ones in the `style` crate because some functions expect generic `SmallVec`s. I also did some reorganisation of the `smallvec` macros. cc @pcwalton
This commit is contained in:
commit
b6c7856926
7 changed files with 85 additions and 127 deletions
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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};
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -1163,7 +1162,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");
|
||||
|
|
|
@ -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;
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
@ -63,10 +62,10 @@ 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,
|
||||
}
|
||||
|
||||
|
@ -74,14 +73,14 @@ 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)
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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),
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
|
|
@ -312,11 +312,7 @@ macro_rules! def_small_vector(
|
|||
ptr: *T,
|
||||
data: [T, ..$size],
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
macro_rules! def_small_vector_private_trait_impl(
|
||||
($name:ident, $size:expr) => (
|
||||
impl<T> SmallVecPrivate<T> for $name<T> {
|
||||
unsafe fn set_len(&mut self, new_len: uint) {
|
||||
self.len = new_len
|
||||
|
@ -342,11 +338,7 @@ macro_rules! def_small_vector_private_trait_impl(
|
|||
self.ptr = cast::transmute(new_ptr)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
macro_rules! def_small_vector_trait_impl(
|
||||
($name:ident, $size:expr) => (
|
||||
impl<T> SmallVec<T> for $name<T> {
|
||||
fn inline_size(&self) -> uint {
|
||||
$size
|
||||
|
@ -358,51 +350,7 @@ macro_rules! def_small_vector_trait_impl(
|
|||
self.cap
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
macro_rules! def_small_vector_drop_impl(
|
||||
($name:ident, $size:expr) => (
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for $name<T> {
|
||||
fn drop(&mut self) {
|
||||
if !self.spilled() {
|
||||
return
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ptr = self.mut_ptr();
|
||||
for i in range(0, self.len()) {
|
||||
*ptr.offset(i as int) = mem::uninit();
|
||||
}
|
||||
|
||||
if intrinsics::owns_managed::<T>() {
|
||||
local_heap::local_free(self.ptr() as *u8)
|
||||
} else {
|
||||
global_heap::exchange_free(self.ptr() as *u8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
macro_rules! def_small_vector_clone_impl(
|
||||
($name:ident) => (
|
||||
impl<T:Clone> Clone for $name<T> {
|
||||
fn clone(&self) -> $name<T> {
|
||||
let mut new_vector = $name::new();
|
||||
for element in self.iter() {
|
||||
new_vector.push((*element).clone())
|
||||
}
|
||||
new_vector
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
macro_rules! def_small_vector_impl(
|
||||
($name:ident, $size:expr) => (
|
||||
impl<T> $name<T> {
|
||||
#[inline]
|
||||
pub fn new() -> $name<T> {
|
||||
|
@ -419,6 +367,14 @@ macro_rules! def_small_vector_impl(
|
|||
)
|
||||
)
|
||||
|
||||
def_small_vector!(SmallVec1, 1)
|
||||
def_small_vector!(SmallVec2, 2)
|
||||
def_small_vector!(SmallVec4, 4)
|
||||
def_small_vector!(SmallVec8, 8)
|
||||
def_small_vector!(SmallVec16, 16)
|
||||
def_small_vector!(SmallVec24, 24)
|
||||
def_small_vector!(SmallVec32, 32)
|
||||
|
||||
/// TODO(pcwalton): Remove in favor of `vec_ng` after a Rust upgrade.
|
||||
pub struct SmallVec0<T> {
|
||||
len: uint,
|
||||
|
@ -472,57 +428,63 @@ impl<T> SmallVec0<T> {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! def_small_vector_drop_impl(
|
||||
($name:ident, $size:expr) => (
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for $name<T> {
|
||||
fn drop(&mut self) {
|
||||
if !self.spilled() {
|
||||
return
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ptr = self.mut_ptr();
|
||||
for i in range(0, self.len()) {
|
||||
*ptr.offset(i as int) = mem::uninit();
|
||||
}
|
||||
|
||||
if intrinsics::owns_managed::<T>() {
|
||||
local_heap::local_free(self.ptr() as *u8)
|
||||
} else {
|
||||
global_heap::exchange_free(self.ptr() as *u8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def_small_vector_drop_impl!(SmallVec0, 0)
|
||||
def_small_vector_clone_impl!(SmallVec0)
|
||||
|
||||
def_small_vector!(SmallVec1, 1)
|
||||
def_small_vector_private_trait_impl!(SmallVec1, 1)
|
||||
def_small_vector_trait_impl!(SmallVec1, 1)
|
||||
def_small_vector_drop_impl!(SmallVec1, 1)
|
||||
def_small_vector_clone_impl!(SmallVec1)
|
||||
def_small_vector_impl!(SmallVec1, 1)
|
||||
|
||||
def_small_vector!(SmallVec2, 2)
|
||||
def_small_vector_private_trait_impl!(SmallVec2, 2)
|
||||
def_small_vector_trait_impl!(SmallVec2, 2)
|
||||
def_small_vector_drop_impl!(SmallVec2, 2)
|
||||
def_small_vector_clone_impl!(SmallVec2)
|
||||
def_small_vector_impl!(SmallVec2, 2)
|
||||
|
||||
def_small_vector!(SmallVec4, 4)
|
||||
def_small_vector_private_trait_impl!(SmallVec4, 4)
|
||||
def_small_vector_trait_impl!(SmallVec4, 4)
|
||||
def_small_vector_drop_impl!(SmallVec4, 4)
|
||||
def_small_vector_clone_impl!(SmallVec4)
|
||||
def_small_vector_impl!(SmallVec4, 4)
|
||||
|
||||
def_small_vector!(SmallVec8, 8)
|
||||
def_small_vector_private_trait_impl!(SmallVec8, 8)
|
||||
def_small_vector_trait_impl!(SmallVec8, 8)
|
||||
def_small_vector_drop_impl!(SmallVec8, 8)
|
||||
def_small_vector_clone_impl!(SmallVec8)
|
||||
def_small_vector_impl!(SmallVec8, 8)
|
||||
|
||||
def_small_vector!(SmallVec16, 16)
|
||||
def_small_vector_private_trait_impl!(SmallVec16, 16)
|
||||
def_small_vector_trait_impl!(SmallVec16, 16)
|
||||
def_small_vector_drop_impl!(SmallVec16, 16)
|
||||
def_small_vector_clone_impl!(SmallVec16)
|
||||
def_small_vector_impl!(SmallVec16, 16)
|
||||
|
||||
def_small_vector!(SmallVec24, 24)
|
||||
def_small_vector_private_trait_impl!(SmallVec24, 24)
|
||||
def_small_vector_trait_impl!(SmallVec24, 24)
|
||||
def_small_vector_drop_impl!(SmallVec24, 24)
|
||||
def_small_vector_clone_impl!(SmallVec24)
|
||||
def_small_vector_impl!(SmallVec24, 24)
|
||||
|
||||
def_small_vector!(SmallVec32, 32)
|
||||
def_small_vector_private_trait_impl!(SmallVec32, 32)
|
||||
def_small_vector_trait_impl!(SmallVec32, 32)
|
||||
def_small_vector_drop_impl!(SmallVec32, 32)
|
||||
|
||||
macro_rules! def_small_vector_clone_impl(
|
||||
($name:ident) => (
|
||||
impl<T:Clone> Clone for $name<T> {
|
||||
fn clone(&self) -> $name<T> {
|
||||
let mut new_vector = $name::new();
|
||||
for element in self.iter() {
|
||||
new_vector.push((*element).clone())
|
||||
}
|
||||
new_vector
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def_small_vector_clone_impl!(SmallVec0)
|
||||
def_small_vector_clone_impl!(SmallVec1)
|
||||
def_small_vector_clone_impl!(SmallVec2)
|
||||
def_small_vector_clone_impl!(SmallVec4)
|
||||
def_small_vector_clone_impl!(SmallVec8)
|
||||
def_small_vector_clone_impl!(SmallVec16)
|
||||
def_small_vector_clone_impl!(SmallVec24)
|
||||
def_small_vector_clone_impl!(SmallVec32)
|
||||
def_small_vector_impl!(SmallVec32, 32)
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue