~[] to Vec in main/compositing and associated files

This commit is contained in:
Matt Murphy 2014-04-20 12:11:19 -05:00 committed by Ms2ger
parent f2707bc405
commit d734a8937d
6 changed files with 57 additions and 57 deletions

View file

@ -361,7 +361,7 @@ impl Font {
}; };
let mut origin = baseline_origin.clone(); let mut origin = baseline_origin.clone();
let mut azglyphs = ~[]; let mut azglyphs = Vec::new();
azglyphs.reserve(range.length()); azglyphs.reserve(range.length());
for (glyphs, _offset, slice_range) in run.iter_slices_for_range(range) { for (glyphs, _offset, slice_range) in run.iter_slices_for_range(range) {

View file

@ -49,8 +49,8 @@ pub struct RenderLayer {
pub enum Msg { pub enum Msg {
RenderMsg(SmallVec1<RenderLayer>), RenderMsg(SmallVec1<RenderLayer>),
ReRenderMsg(~[BufferRequest], f32, LayerId, Epoch), ReRenderMsg(Vec<BufferRequest>, f32, LayerId, Epoch),
UnusedBufferMsg(~[~LayerBuffer]), UnusedBufferMsg(Vec<~LayerBuffer>),
PaintPermissionGranted, PaintPermissionGranted,
PaintPermissionRevoked, PaintPermissionRevoked,
ExitMsg(Option<Sender<()>>), ExitMsg(Option<Sender<()>>),
@ -256,8 +256,7 @@ impl<C: RenderListener + Send> RenderTask<C> {
} }
} }
UnusedBufferMsg(unused_buffers) => { UnusedBufferMsg(unused_buffers) => {
// move_rev_iter is more efficient for buffer in unused_buffers.move_iter() {
for buffer in unused_buffers.move_rev_iter() {
self.buffer_map.insert(native_graphics_context!(self), buffer); self.buffer_map.insert(native_graphics_context!(self), buffer);
} }
} }
@ -291,10 +290,10 @@ impl<C: RenderListener + Send> RenderTask<C> {
/// ///
/// FIXME(pcwalton): We will probably want to eventually send all layers belonging to a page in /// FIXME(pcwalton): We will probably want to eventually send all layers belonging to a page in
/// one transaction, to avoid the user seeing inconsistent states. /// one transaction, to avoid the user seeing inconsistent states.
fn render(&mut self, tiles: ~[BufferRequest], scale: f32, layer_id: LayerId) { fn render(&mut self, tiles: Vec<BufferRequest>, scale: f32, layer_id: LayerId) {
time::profile(time::RenderingCategory, self.profiler_chan.clone(), || { time::profile(time::RenderingCategory, self.profiler_chan.clone(), || {
// FIXME: Try not to create a new array here. // FIXME: Try not to create a new array here.
let mut new_buffers = ~[]; let mut new_buffers = Vec::new();
// Find the appropriate render layer. // Find the appropriate render layer.
let render_layer = match self.render_layers.iter().find(|layer| layer.id == layer_id) { let render_layer = match self.render_layers.iter().find(|layer| layer.id == layer_id) {

View file

@ -841,8 +841,8 @@ impl CompositorLayer {
Tree(ref mut quadtree) => quadtree, Tree(ref mut quadtree) => quadtree,
}; };
let mut unused_tiles = ~[]; let mut unused_tiles = Vec::new();
for buffer in new_buffers.buffers.move_rev_iter() { for buffer in new_buffers.buffers.move_iter() {
unused_tiles.push_all_move(quadtree.add_tile_pixel(buffer.screen_pos.origin.x, unused_tiles.push_all_move(quadtree.add_tile_pixel(buffer.screen_pos.origin.x,
buffer.screen_pos.origin.y, buffer.screen_pos.origin.y,
buffer.resolution, buffer.resolution,

View file

@ -109,7 +109,7 @@ impl<T: Tile> Quadtree<T> {
/// Add a tile associated with a given pixel position and scale. /// Add a tile associated with a given pixel position and scale.
/// If the tile pushes the total memory over its maximum, tiles will be removed /// If the tile pushes the total memory over its maximum, tiles will be removed
/// until total memory is below the maximum again. These tiles are returned. /// until total memory is below the maximum again. These tiles are returned.
pub fn add_tile_pixel(&mut self, x: uint, y: uint, scale: f32, tile: T) -> ~[T] { pub fn add_tile_pixel(&mut self, x: uint, y: uint, scale: f32, tile: T) -> Vec<T> {
let (_, tiles) = self.root.add_tile(x as f32 / scale, y as f32 / scale, tile, let (_, tiles) = self.root.add_tile(x as f32 / scale, y as f32 / scale, tile,
self.max_tile_size as f32 / scale); self.max_tile_size as f32 / scale);
let mut tiles = tiles; let mut tiles = tiles;
@ -129,7 +129,7 @@ impl<T: Tile> Quadtree<T> {
} }
/// Get all the tiles in the tree. /// Get all the tiles in the tree.
pub fn get_all_tiles<'r>(&'r self) -> ~[&'r T] { pub fn get_all_tiles<'r>(&'r self) -> Vec<&'r T> {
self.root.get_all_tiles() self.root.get_all_tiles()
} }
@ -139,7 +139,7 @@ impl<T: Tile> Quadtree<T> {
/// user zooms out and cached tiles need to be displayed on top of higher resolution tiles. /// user zooms out and cached tiles need to be displayed on top of higher resolution tiles.
/// When this happens, higher resolution tiles will be removed from the quadtree. /// When this happens, higher resolution tiles will be removed from the quadtree.
#[cfg(test)] #[cfg(test)]
pub fn get_tile_rects_pixel(&mut self, window: Rect<int>, scale: f32) -> (~[BufferRequest], ~[T]) { pub fn get_tile_rects_pixel(&mut self, window: Rect<int>, scale: f32) -> (Vec<BufferRequest>, Vec<T>) {
let (ret, unused, _) = self.root.get_tile_rects( let (ret, unused, _) = self.root.get_tile_rects(
Rect(Point2D(window.origin.x as f32 / scale, window.origin.y as f32 / scale), Rect(Point2D(window.origin.x as f32 / scale, window.origin.y as f32 / scale),
Size2D(window.size.width as f32 / scale, window.size.height as f32 / scale)), Size2D(window.size.width as f32 / scale, window.size.height as f32 / scale)),
@ -149,7 +149,7 @@ impl<T: Tile> Quadtree<T> {
} }
/// Same function as above, using page coordinates for the window. /// Same function as above, using page coordinates for the window.
pub fn get_tile_rects_page(&mut self, window: Rect<f32>, scale: f32) -> (~[BufferRequest], ~[T]) { pub fn get_tile_rects_page(&mut self, window: Rect<f32>, scale: f32) -> (Vec<BufferRequest>, Vec<T>) {
let (ret, unused, _) = self.root.get_tile_rects( let (ret, unused, _) = self.root.get_tile_rects(
window, window,
Size2D(self.clip_size.width as f32, self.clip_size.height as f32), Size2D(self.clip_size.width as f32, self.clip_size.height as f32),
@ -158,7 +158,7 @@ impl<T: Tile> Quadtree<T> {
} }
/// Creates a new quadtree at the specified size. This should be called when the window changes size. /// Creates a new quadtree at the specified size. This should be called when the window changes size.
pub fn resize(&mut self, width: uint, height: uint) -> ~[T] { pub fn resize(&mut self, width: uint, height: uint) -> Vec<T> {
// Spaces must be squares and powers of 2, so expand the space until it is // Spaces must be squares and powers of 2, so expand the space until it is
let longer = cmp::max(width, height); let longer = cmp::max(width, height);
let num_tiles = div_ceil(longer, self.max_tile_size); let num_tiles = div_ceil(longer, self.max_tile_size);
@ -234,7 +234,7 @@ impl<T: Tile> Quadtree<T> {
/// Remove and return all tiles in the tree. Use this before deleting the quadtree to prevent /// Remove and return all tiles in the tree. Use this before deleting the quadtree to prevent
/// a GC pause. /// a GC pause.
pub fn collect_tiles(&mut self) -> ~[T] { pub fn collect_tiles(&mut self) -> Vec<T> {
self.root.collect_tiles() self.root.collect_tiles()
} }
} }
@ -268,17 +268,17 @@ impl<T: Tile> QuadtreeNode<T> {
} }
/// Get all tiles in the tree, parents first. /// Get all tiles in the tree, parents first.
fn get_all_tiles<'r>(&'r self) -> ~[&'r T] { fn get_all_tiles<'r>(&'r self) -> Vec<&'r T> {
let mut ret = ~[]; let mut ret = Vec::new();
match self.tile { match self.tile {
Some(ref tile) => ret = ret + ~[tile], Some(ref tile) => ret.push(tile),
None => {} None => {}
} }
for quad in self.quadrants.iter() { for quad in self.quadrants.iter() {
match *quad { match *quad {
Some(ref child) => ret = ret + child.get_all_tiles(), Some(ref child) => ret.push_all_move(child.get_all_tiles()),
None => {} None => {}
} }
} }
@ -290,7 +290,7 @@ impl<T: Tile> QuadtreeNode<T> {
/// the node will be split and the method will recurse until the tile size is within limits. /// the node will be split and the method will recurse until the tile size is within limits.
/// Returns an the difference in tile memory between the new quadtree node and the old quadtree node, /// Returns an the difference in tile memory between the new quadtree node and the old quadtree node,
/// along with any deleted tiles. /// along with any deleted tiles.
fn add_tile(&mut self, x: f32, y: f32, tile: T, tile_size: f32) -> (int, ~[T]) { fn add_tile(&mut self, x: f32, y: f32, tile: T, tile_size: f32) -> (int, Vec<T>) {
debug!("Quadtree: Adding: ({}, {}) size:{}px", self.origin.x, self.origin.y, self.size); debug!("Quadtree: Adding: ({}, {}) size:{}px", self.origin.x, self.origin.y, self.size);
if x >= self.origin.x + self.size || x < self.origin.x if x >= self.origin.x + self.size || x < self.origin.x
@ -302,8 +302,8 @@ impl<T: Tile> QuadtreeNode<T> {
let old_size = self.tile_mem; let old_size = self.tile_mem;
self.tile_mem = tile.get_mem(); self.tile_mem = tile.get_mem();
let mut unused_tiles = match replace(&mut self.tile, Some(tile)) { let mut unused_tiles = match replace(&mut self.tile, Some(tile)) {
Some(old_tile) => ~[old_tile], Some(old_tile) => vec!(old_tile),
None => ~[], None => Vec::new(),
}; };
for child in self.quadrants.mut_iter() { for child in self.quadrants.mut_iter() {
match *child { match *child {
@ -466,7 +466,7 @@ impl<T: Tile> QuadtreeNode<T> {
scale: f32, scale: f32,
tile_size: f32, tile_size: f32,
override: bool) override: bool)
-> (~[BufferRequest], ~[T], int) { -> (Vec<BufferRequest>, Vec<T>, int) {
let w_x = window.origin.x; let w_x = window.origin.x;
let w_y = window.origin.y; let w_y = window.origin.y;
let w_width = window.size.width; let w_width = window.size.width;
@ -479,7 +479,7 @@ impl<T: Tile> QuadtreeNode<T> {
if w_x + w_width < s_x || w_x > s_x + s_size if w_x + w_width < s_x || w_x > s_x + s_size
|| w_y + w_height < s_y || w_y > s_y + s_size || w_y + w_height < s_y || w_y > s_y + s_size
|| w_x >= clip.width || w_y >= clip.height { || w_x >= clip.width || w_y >= clip.height {
return (~[], ~[], 0); return (Vec::new(), Vec::new(), 0);
} }
// clip window to visible region // clip window to visible region
@ -488,7 +488,7 @@ impl<T: Tile> QuadtreeNode<T> {
if s_size <= tile_size { // We are the child if s_size <= tile_size { // We are the child
return match self.tile { return match self.tile {
_ if self.status == Rendering || self.status == Hidden => (~[], ~[], 0), _ if self.status == Rendering || self.status == Hidden => (Vec::new(), Vec::new(), 0),
Some(ref tile) if tile.is_valid(scale) && !override Some(ref tile) if tile.is_valid(scale) && !override
&& self.status != Invalid => { && self.status != Invalid => {
let redisplay = match self.quadrants { let redisplay = match self.quadrants {
@ -496,7 +496,7 @@ impl<T: Tile> QuadtreeNode<T> {
_ => true, _ => true,
}; };
let mut delta = 0; let mut delta = 0;
let mut unused_tiles = ~[]; let mut unused_tiles = Vec::new();
if redisplay { if redisplay {
let old_mem = self.tile_mem; let old_mem = self.tile_mem;
for child in self.quadrants.mut_iter() { for child in self.quadrants.mut_iter() {
@ -512,9 +512,9 @@ impl<T: Tile> QuadtreeNode<T> {
delta = self.tile_mem as int - old_mem as int; delta = self.tile_mem as int - old_mem as int;
} }
(~[], unused_tiles, delta) (Vec::new(), unused_tiles, delta)
} }
_ => (~[self.get_tile_rect(s_x, s_y, clip.width, clip.height, scale, tile_size)], ~[], 0), _ => (vec!(self.get_tile_rect(s_x, s_y, clip.width, clip.height, scale, tile_size)), Vec::new(), 0),
} }
} }
@ -548,8 +548,8 @@ impl<T: Tile> QuadtreeNode<T> {
let quads_to_check = slice::build(Some(4), builder); let quads_to_check = slice::build(Some(4), builder);
let mut request = ~[]; let mut request = Vec::new();
let mut unused = ~[]; let mut unused = Vec::new();
let mut delta = 0; let mut delta = 0;
for quad in quads_to_check.iter() { for quad in quads_to_check.iter() {
@ -596,7 +596,8 @@ impl<T: Tile> QuadtreeNode<T> {
}; };
delta = delta + c_delta; delta = delta + c_delta;
request = request + c_request; // This was a ~[] = ~[] + ~[] which copies. I think this is the equivalent operation.
request.push_all(c_request.as_slice());
unused.push_all_move(c_unused); unused.push_all_move(c_unused);
} }
self.tile_mem = (self.tile_mem as int + delta) as uint; self.tile_mem = (self.tile_mem as int + delta) as uint;
@ -604,10 +605,10 @@ impl<T: Tile> QuadtreeNode<T> {
} }
/// Remove all tiles from the tree. Use this to collect all tiles before deleting a branch. /// Remove all tiles from the tree. Use this to collect all tiles before deleting a branch.
fn collect_tiles(&mut self) -> ~[T] { fn collect_tiles(&mut self) -> Vec<T> {
let mut ret = match replace(&mut self.tile, None) { let mut ret = match replace(&mut self.tile, None) {
Some(tile) => ~[tile], Some(tile) => vec!(tile),
None => ~[], None => Vec::new(),
}; };
for child in self.quadrants.mut_iter() { for child in self.quadrants.mut_iter() {
match *child { match *child {

View file

@ -35,7 +35,7 @@ pub struct LayerBuffer {
/// A set of layer buffers. This is an atomic unit used to switch between the front and back /// A set of layer buffers. This is an atomic unit used to switch between the front and back
/// buffers. /// buffers.
pub struct LayerBufferSet { pub struct LayerBufferSet {
pub buffers: ~[~LayerBuffer] pub buffers: Vec<~LayerBuffer>
} }
impl LayerBufferSet { impl LayerBufferSet {

View file

@ -584,11 +584,11 @@ mod tests {
use namespaces::NamespaceMap; use namespaces::NamespaceMap;
use super::*; use super::*;
fn parse(input: &str) -> Option<~[Selector]> { fn parse(input: &str) -> Option<Vec<Selector>> {
parse_ns(input, &NamespaceMap::new()) parse_ns(input, &NamespaceMap::new())
} }
fn parse_ns(input: &str, namespaces: &NamespaceMap) -> Option<~[Selector]> { fn parse_ns(input: &str, namespaces: &NamespaceMap) -> Option<Vec<Selector>> {
parse_selector_list( parse_selector_list(
cssparser::tokenize(input).map(|(v, _)| v).collect(), cssparser::tokenize(input).map(|(v, _)| v).collect(),
namespaces) namespaces)
@ -601,31 +601,31 @@ mod tests {
#[test] #[test]
fn test_parsing() { fn test_parsing() {
assert!(parse("") == None) assert!(parse("") == None)
assert!(parse("e") == Some(~[Selector{ assert!(parse("e") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[LocalNameSelector("e".to_owned())], simple_selectors: ~[LocalNameSelector("e".to_owned())],
next: None, next: None,
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(0, 0, 1), specificity: specificity(0, 0, 1),
}])) })))
assert!(parse(".foo") == Some(~[Selector{ assert!(parse(".foo") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[ClassSelector("foo".to_owned())], simple_selectors: ~[ClassSelector("foo".to_owned())],
next: None, next: None,
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(0, 1, 0), specificity: specificity(0, 1, 0),
}])) })))
assert!(parse("#bar") == Some(~[Selector{ assert!(parse("#bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[IDSelector("bar".to_owned())], simple_selectors: ~[IDSelector("bar".to_owned())],
next: None, next: None,
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(1, 0, 0), specificity: specificity(1, 0, 0),
}])) })))
assert!(parse("e.foo#bar") == Some(~[Selector{ assert!(parse("e.foo#bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[LocalNameSelector("e".to_owned()), simple_selectors: ~[LocalNameSelector("e".to_owned()),
ClassSelector("foo".to_owned()), ClassSelector("foo".to_owned()),
@ -634,8 +634,8 @@ mod tests {
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(1, 1, 1), specificity: specificity(1, 1, 1),
}])) })))
assert!(parse("e.foo #bar") == Some(~[Selector{ assert!(parse("e.foo #bar") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[IDSelector("bar".to_owned())], simple_selectors: ~[IDSelector("bar".to_owned())],
next: Some((~CompoundSelector { next: Some((~CompoundSelector {
@ -646,11 +646,11 @@ mod tests {
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(1, 1, 1), specificity: specificity(1, 1, 1),
}])) })))
// Default namespace does not apply to attribute selectors // Default namespace does not apply to attribute selectors
// https://github.com/mozilla/servo/pull/1652 // https://github.com/mozilla/servo/pull/1652
let mut namespaces = NamespaceMap::new(); let mut namespaces = NamespaceMap::new();
assert!(parse_ns("[Foo]", &namespaces) == Some(~[Selector{ assert!(parse_ns("[Foo]", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[AttrExists(AttrSelector { simple_selectors: ~[AttrExists(AttrSelector {
name: "Foo".to_owned(), name: "Foo".to_owned(),
@ -661,11 +661,11 @@ mod tests {
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(0, 1, 0), specificity: specificity(0, 1, 0),
}])) })))
// Default namespace does not apply to attribute selectors // Default namespace does not apply to attribute selectors
// https://github.com/mozilla/servo/pull/1652 // https://github.com/mozilla/servo/pull/1652
namespaces.default = Some(namespace::MathML); namespaces.default = Some(namespace::MathML);
assert!(parse_ns("[Foo]", &namespaces) == Some(~[Selector{ assert!(parse_ns("[Foo]", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[AttrExists(AttrSelector { simple_selectors: ~[AttrExists(AttrSelector {
name: "Foo".to_owned(), name: "Foo".to_owned(),
@ -676,9 +676,9 @@ mod tests {
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(0, 1, 0), specificity: specificity(0, 1, 0),
}])) })))
// Default namespace does apply to type selectors // Default namespace does apply to type selectors
assert!(parse_ns("e", &namespaces) == Some(~[Selector{ assert!(parse_ns("e", &namespaces) == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[ simple_selectors: ~[
NamespaceSelector(namespace::MathML), NamespaceSelector(namespace::MathML),
@ -688,17 +688,17 @@ mod tests {
}), }),
pseudo_element: None, pseudo_element: None,
specificity: specificity(0, 0, 1), specificity: specificity(0, 0, 1),
}])) })))
// https://github.com/mozilla/servo/issues/1723 // https://github.com/mozilla/servo/issues/1723
assert!(parse("::before") == Some(~[Selector{ assert!(parse("::before") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[], simple_selectors: ~[],
next: None, next: None,
}), }),
pseudo_element: Some(Before), pseudo_element: Some(Before),
specificity: specificity(0, 0, 1), specificity: specificity(0, 0, 1),
}])) })))
assert!(parse("div :after") == Some(~[Selector{ assert!(parse("div :after") == Some(vec!(Selector{
compound_selectors: Arc::new(CompoundSelector { compound_selectors: Arc::new(CompoundSelector {
simple_selectors: ~[], simple_selectors: ~[],
next: Some((~CompoundSelector { next: Some((~CompoundSelector {
@ -708,6 +708,6 @@ mod tests {
}), }),
pseudo_element: Some(After), pseudo_element: Some(After),
specificity: specificity(0, 0, 2), specificity: specificity(0, 0, 2),
}])) })))
} }
} }