diff options
Diffstat (limited to 'src')
40 files changed, 367 insertions, 317 deletions
diff --git a/src/components/gfx/buffer_map.rs b/src/components/gfx/buffer_map.rs index 899e077a93d..9b3a6f60988 100644 --- a/src/components/gfx/buffer_map.rs +++ b/src/components/gfx/buffer_map.rs @@ -54,7 +54,7 @@ impl BufferKey { /// A helper struct to keep track of buffers in the HashMap struct BufferValue<T> { /// An array of buffers, all the same size - buffers: ~[T], + buffers: Vec<T>, /// The counter when this size was last requested last_action: uint, } @@ -86,7 +86,7 @@ impl<T: Tile> BufferMap<T> { // use lazy insertion function to prevent unnecessary allocation let counter = &self.counter; self.map.find_or_insert_with(new_key, |_| BufferValue { - buffers: ~[], + buffers: vec!(), last_action: *counter }).buffers.push(new_buffer); diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index 9f00a883098..aa389e00664 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -101,7 +101,7 @@ pub struct FontStyle { pub pt_size: f64, pub weight: font_weight::T, pub style: font_style::T, - pub families: ~[~str], + pub families: Vec<~str>, // TODO(Issue #198): font-stretch, text-decoration, font-variant, size-adjust } @@ -143,15 +143,15 @@ pub enum FontSelector { // The ordering of font instances is mainly decided by the CSS // 'font-family' property. The last font is a system fallback font. pub struct FontGroup { - pub families: ~[~str], + pub families: Vec<~str>, // style of the first western font in group, which is // used for purposes of calculating text run metrics. pub style: UsedFontStyle, - pub fonts: ~[Rc<RefCell<Font>>] + pub fonts: Vec<Rc<RefCell<Font>>> } impl FontGroup { - pub fn new(families: ~[~str], style: &UsedFontStyle, fonts: ~[Rc<RefCell<Font>>]) -> FontGroup { + pub fn new(families: Vec<~str>, style: &UsedFontStyle, fonts: Vec<Rc<RefCell<Font>>>) -> FontGroup { FontGroup { families: families, style: (*style).clone(), @@ -160,14 +160,14 @@ impl FontGroup { } pub fn teardown(&mut self) { - self.fonts = ~[]; + self.fonts = vec!(); } pub fn create_textrun(&self, text: ~str, decoration: text_decoration::T) -> TextRun { assert!(self.fonts.len() > 0); // TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable. - TextRun::new(&mut *self.fonts[0].borrow_mut(), text.clone(), decoration) + TextRun::new(&mut *self.fonts.get(0).borrow_mut(), text.clone(), decoration) } } @@ -361,7 +361,7 @@ impl Font { }; let mut origin = baseline_origin.clone(); - let mut azglyphs = ~[]; + let mut azglyphs = vec!(); azglyphs.reserve(range.length()); for (glyphs, _offset, slice_range) in run.iter_slices_for_range(range) { diff --git a/src/components/gfx/font_context.rs b/src/components/gfx/font_context.rs index 75ae81ac659..021a1b57996 100644 --- a/src/components/gfx/font_context.rs +++ b/src/components/gfx/font_context.rs @@ -116,7 +116,7 @@ impl FontContext { } fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> Rc<RefCell<FontGroup>> { - let mut fonts = ~[]; + let mut fonts = vec!(); debug!("(create font group) --- starting ---"); @@ -200,7 +200,7 @@ impl FontContext { Rc::new( RefCell::new( - FontGroup::new(style.families.to_owned(), &used_style, fonts))) + FontGroup::new(style.families.clone(), &used_style, fonts))) } fn create_font_instance(&self, desc: &FontDescriptor) -> Result<Rc<RefCell<Font>>, ()> { diff --git a/src/components/gfx/font_list.rs b/src/components/gfx/font_list.rs index a2193bec0e7..ceda9619eb5 100644 --- a/src/components/gfx/font_list.rs +++ b/src/components/gfx/font_list.rs @@ -84,14 +84,14 @@ impl FontList { // Holds a specific font family, and the various pub struct FontFamily { pub family_name: ~str, - pub entries: ~[FontEntry], + pub entries: Vec<FontEntry>, } impl FontFamily { pub fn new(family_name: &str) -> FontFamily { FontFamily { family_name: family_name.to_str(), - entries: ~[], + entries: vec!(), } } diff --git a/src/components/gfx/render_task.rs b/src/components/gfx/render_task.rs index 824be82f7bd..6d38286c0f9 100644 --- a/src/components/gfx/render_task.rs +++ b/src/components/gfx/render_task.rs @@ -49,8 +49,8 @@ pub struct RenderLayer { pub enum Msg { RenderMsg(SmallVec1<RenderLayer>), - ReRenderMsg(~[BufferRequest], f32, LayerId, Epoch), - UnusedBufferMsg(~[~LayerBuffer]), + ReRenderMsg(Vec<BufferRequest>, f32, LayerId, Epoch), + UnusedBufferMsg(Vec<~LayerBuffer>), PaintPermissionGranted, PaintPermissionRevoked, ExitMsg(Option<Sender<()>>), @@ -256,8 +256,7 @@ impl<C: RenderListener + Send> RenderTask<C> { } } UnusedBufferMsg(unused_buffers) => { - // move_rev_iter is more efficient - for buffer in unused_buffers.move_rev_iter() { + for buffer in unused_buffers.move_iter().rev() { 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 /// 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(), || { // FIXME: Try not to create a new array here. - let mut new_buffers = ~[]; + let mut new_buffers = vec!(); // Find the appropriate render layer. let render_layer = match self.render_layers.iter().find(|layer| layer.id == layer_id) { diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs index a4fd127bbd5..1d1b99a8abc 100644 --- a/src/components/gfx/text/glyph.rs +++ b/src/components/gfx/text/glyph.rs @@ -300,18 +300,18 @@ impl Ord for DetailedGlyphRecord { struct DetailedGlyphStore { // TODO(pcwalton): Allocation of this buffer is expensive. Consider a small-vector // optimization. - detail_buffer: ~[DetailedGlyph], + detail_buffer: Vec<DetailedGlyph>, // TODO(pcwalton): Allocation of this buffer is expensive. Consider a small-vector // optimization. - detail_lookup: ~[DetailedGlyphRecord], + detail_lookup: Vec<DetailedGlyphRecord>, lookup_is_sorted: bool, } impl<'a> DetailedGlyphStore { fn new() -> DetailedGlyphStore { DetailedGlyphStore { - detail_buffer: ~[], // TODO: default size? - detail_lookup: ~[], + detail_buffer: vec!(), // TODO: default size? + detail_lookup: vec!(), lookup_is_sorted: false } } @@ -359,7 +359,7 @@ impl<'a> DetailedGlyphStore { }; // FIXME: This is a workaround for borrow of self.detail_lookup not getting inferred. - let records : &[DetailedGlyphRecord] = self.detail_lookup; + let records : &[DetailedGlyphRecord] = self.detail_lookup.as_slice(); match records.binary_search_index(&key) { None => fail!("Invalid index not found in detailed glyph lookup table!"), Some(i) => { @@ -383,12 +383,12 @@ impl<'a> DetailedGlyphStore { }; // FIXME: This is a workaround for borrow of self.detail_lookup not getting inferred. - let records: &[DetailedGlyphRecord] = self.detail_lookup; + let records: &[DetailedGlyphRecord] = self.detail_lookup.as_slice(); match records.binary_search_index(&key) { None => fail!("Invalid index not found in detailed glyph lookup table!"), Some(i) => { assert!(i + (detail_offset as uint) < self.detail_buffer.len()); - &self.detail_buffer[i+(detail_offset as uint)] + self.detail_buffer.get(i+(detail_offset as uint)) } } } @@ -403,9 +403,9 @@ impl<'a> DetailedGlyphStore { // immutable locations thus don't play well with freezing. // Thar be dragons here. You have been warned. (Tips accepted.) - let mut unsorted_records: ~[DetailedGlyphRecord] = ~[]; + let mut unsorted_records: Vec<DetailedGlyphRecord> = vec!(); mem::swap(&mut self.detail_lookup, &mut unsorted_records); - let mut mut_records : ~[DetailedGlyphRecord] = unsorted_records; + let mut mut_records : Vec<DetailedGlyphRecord> = unsorted_records; mut_records.sort_by(|a, b| { if a < b { Less diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index 45423eedf5a..6a89a335911 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -411,7 +411,7 @@ impl Shaper { glyphs.add_glyph_for_char_index(char_idx, &data); } else { // collect all glyphs to be assigned to the first character. - let mut datas = ~[]; + let mut datas = vec!(); for glyph_i in glyph_span.eachi() { let shape = glyph_data.get_entry_for_glyph(glyph_i, &mut y_pos); @@ -425,7 +425,7 @@ impl Shaper { } // now add the detailed glyph entry. - glyphs.add_glyphs_for_char_index(char_idx, datas); + glyphs.add_glyphs_for_char_index(char_idx, datas.as_slice()); // set the other chars, who have no glyphs let mut i = covered_byte_span.begin(); diff --git a/src/components/gfx/text/text_run.rs b/src/components/gfx/text/text_run.rs index 0316dd37bb7..e65ef22c264 100644 --- a/src/components/gfx/text/text_run.rs +++ b/src/components/gfx/text/text_run.rs @@ -18,7 +18,7 @@ pub struct TextRun { pub font_metrics: FontMetrics, pub font_style: FontStyle, pub decoration: text_decoration::T, - pub glyphs: Arc<~[Arc<GlyphStore>]>, + pub glyphs: Arc<Vec<Arc<GlyphStore>>>, } pub struct SliceIterator<'a> { @@ -113,10 +113,10 @@ impl<'a> TextRun { pub fn teardown(&self) { } - pub fn break_and_shape(font: &mut Font, text: &str) -> ~[Arc<GlyphStore>] { + pub fn break_and_shape(font: &mut Font, text: &str) -> Vec<Arc<GlyphStore>> { // TODO(Issue #230): do a better job. See Gecko's LineBreaker. - let mut glyphs = ~[]; + let mut glyphs = vec!(); let mut byte_i = 0u; let mut cur_slice_is_whitespace = false; let mut byte_last_boundary = 0; @@ -174,7 +174,7 @@ impl<'a> TextRun { }) } - pub fn glyphs(&'a self) -> &'a ~[Arc<GlyphStore>] { + pub fn glyphs(&'a self) -> &'a Vec<Arc<GlyphStore>> { &*self.glyphs } diff --git a/src/components/gfx/text/util.rs b/src/components/gfx/text/util.rs index 79cbc6930c3..1f4fa172018 100644 --- a/src/components/gfx/text/util.rs +++ b/src/components/gfx/text/util.rs @@ -20,7 +20,7 @@ pub enum CompressionMode { // * Issue #114: record skipped and kept chars for mapping original to new text // // * Untracked: various edge cases for bidi, CJK, etc. -pub fn transform_text(text: &str, mode: CompressionMode, incoming_whitespace: bool, new_line_pos: &mut ~[uint]) -> (~str, bool) { +pub fn transform_text(text: &str, mode: CompressionMode, incoming_whitespace: bool, new_line_pos: &mut Vec<uint>) -> (~str, bool) { let mut out_str: ~str = "".to_owned(); let out_whitespace = match mode { CompressNone | DiscardNewline => { @@ -149,7 +149,7 @@ fn test_transform_compress_none() { let mode = CompressNone; for i in range(0, test_strs.len()) { - let mut new_line_pos = ~[]; + let mut new_line_pos = vec!(); let (trimmed_str, _out) = transform_text(test_strs[i], mode, true, &mut new_line_pos); assert_eq!(&trimmed_str, &test_strs[i]) } @@ -178,7 +178,7 @@ fn test_transform_discard_newline() { let mode = DiscardNewline; for i in range(0, test_strs.len()) { - let mut new_line_pos = ~[]; + let mut new_line_pos = vec!(); let (trimmed_str, _out) = transform_text(test_strs[i], mode, true, &mut new_line_pos); assert_eq!(&trimmed_str, &oracle_strs[i]) } @@ -266,7 +266,7 @@ fn test_transform_compress_whitespace_newline_no_incoming() { let mode = CompressWhitespaceNewline; for i in range(0, test_strs.len()) { - let mut new_line_pos = ~[]; + let mut new_line_pos = vec!(); let (trimmed_str, _out) = transform_text(test_strs[i], mode, false, &mut new_line_pos); assert_eq!(&trimmed_str, &oracle_strs[i]) } diff --git a/src/components/main/compositing/compositor_layer.rs b/src/components/main/compositing/compositor_layer.rs index 2294bdbf10d..160024c1815 100644 --- a/src/components/main/compositing/compositor_layer.rs +++ b/src/components/main/compositing/compositor_layer.rs @@ -65,7 +65,7 @@ pub struct CompositorLayer { /// differs in scroll behavior from its parent. Each is associated with a /// ContainerLayer which determines its position relative to its parent and /// clipping rect. Children are stored in the order in which they are drawn. - pub children: ~[CompositorLayerChild], + pub children: Vec<CompositorLayerChild>, /// This layer's quadtree. This is where all buffers are stored for this layer. pub quadtree: MaybeQuadtree, @@ -170,7 +170,7 @@ impl CompositorLayer { bounds: bounds, page_size: page_size, scroll_offset: Point2D(0f32, 0f32), - children: ~[], + children: vec!(), quadtree: match page_size { None => NoTree(tile_size, Some(MAX_TILE_MEMORY_PER_LAYER)), Some(page_size) => { @@ -203,7 +203,7 @@ impl CompositorLayer { bounds: Rect(Point2D(0f32, 0f32), page_size), page_size: Some(page_size), scroll_offset: Point2D(0f32, 0f32), - children: ~[], + children: vec!(), quadtree: NoTree(tile_size, Some(MAX_TILE_MEMORY_PER_LAYER)), root_layer: Rc::new(ContainerLayer()), hidden: false, @@ -494,7 +494,7 @@ impl CompositorLayer { }) { Some(i) => { debug!("compositor_layer: node found for set_clipping_rect()"); - let child_node = &mut self.children[i]; + let child_node = self.children.get_mut(i); child_node.container.common.borrow_mut().set_transform( identity().translate(new_rect.origin.x, new_rect.origin.y, 0.0)); let old_rect = child_node.container.scissor.borrow().clone(); @@ -649,7 +649,7 @@ impl CompositorLayer { }) { Some(i) => { debug!("compositor_layer: layer found for resize_helper()"); - let child_node = &mut self.children[i]; + let child_node = self.children.get_mut(i); let child = &mut child_node.child; child.epoch = epoch; child.page_size = Some(new_size); @@ -841,8 +841,8 @@ impl CompositorLayer { Tree(ref mut quadtree) => quadtree, }; - let mut unused_tiles = ~[]; - for buffer in new_buffers.buffers.move_rev_iter() { + let mut unused_tiles = vec!(); + for buffer in new_buffers.buffers.move_iter().rev() { unused_tiles.push_all_move(quadtree.add_tile_pixel(buffer.screen_pos.origin.x, buffer.screen_pos.origin.y, buffer.resolution, diff --git a/src/components/main/compositing/quadtree.rs b/src/components/main/compositing/quadtree.rs index 5c3ffa34a92..8e5354aff61 100644 --- a/src/components/main/compositing/quadtree.rs +++ b/src/components/main/compositing/quadtree.rs @@ -109,7 +109,7 @@ impl<T: Tile> Quadtree<T> { /// 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 /// 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, self.max_tile_size as f32 / scale); let mut tiles = tiles; @@ -129,7 +129,7 @@ impl<T: Tile> Quadtree<T> { } /// 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() } @@ -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. /// When this happens, higher resolution tiles will be removed from the quadtree. #[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( 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)), @@ -149,7 +149,7 @@ impl<T: Tile> Quadtree<T> { } /// 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( window, 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. - 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 let longer = cmp::max(width, height); 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 /// a GC pause. - pub fn collect_tiles(&mut self) -> ~[T] { + pub fn collect_tiles(&mut self) -> Vec<T> { self.root.collect_tiles() } } @@ -268,17 +268,17 @@ impl<T: Tile> QuadtreeNode<T> { } /// Get all tiles in the tree, parents first. - fn get_all_tiles<'r>(&'r self) -> ~[&'r T] { - let mut ret = ~[]; + fn get_all_tiles<'r>(&'r self) -> Vec<&'r T> { + let mut ret = vec!(); match self.tile { - Some(ref tile) => ret = ret + ~[tile], + Some(ref tile) => ret.push(tile), None => {} } for quad in self.quadrants.iter() { match *quad { - Some(ref child) => ret = ret + child.get_all_tiles(), + Some(ref child) => ret.push_all_move(child.get_all_tiles()), 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. /// Returns an the difference in tile memory between the new quadtree node and the old quadtree node, /// 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); 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; self.tile_mem = tile.get_mem(); let mut unused_tiles = match replace(&mut self.tile, Some(tile)) { - Some(old_tile) => ~[old_tile], - None => ~[], + Some(old_tile) => vec!(old_tile), + None => vec!(), }; for child in self.quadrants.mut_iter() { match *child { @@ -466,7 +466,7 @@ impl<T: Tile> QuadtreeNode<T> { scale: f32, tile_size: f32, override: bool) - -> (~[BufferRequest], ~[T], int) { + -> (Vec<BufferRequest>, Vec<T>, int) { let w_x = window.origin.x; let w_y = window.origin.y; 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 || w_y + w_height < s_y || w_y > s_y + s_size || w_x >= clip.width || w_y >= clip.height { - return (~[], ~[], 0); + return (vec!(), vec!(), 0); } // clip window to visible region @@ -488,7 +488,7 @@ impl<T: Tile> QuadtreeNode<T> { if s_size <= tile_size { // We are the child return match self.tile { - _ if self.status == Rendering || self.status == Hidden => (~[], ~[], 0), + _ if self.status == Rendering || self.status == Hidden => (vec!(), vec!(), 0), Some(ref tile) if tile.is_valid(scale) && !override && self.status != Invalid => { let redisplay = match self.quadrants { @@ -496,7 +496,7 @@ impl<T: Tile> QuadtreeNode<T> { _ => true, }; let mut delta = 0; - let mut unused_tiles = ~[]; + let mut unused_tiles = vec!(); if redisplay { let old_mem = self.tile_mem; 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; } - (~[], unused_tiles, delta) + (vec!(), 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!(), 0), } } @@ -548,8 +548,8 @@ impl<T: Tile> QuadtreeNode<T> { let quads_to_check = slice::build(Some(4), builder); - let mut request = ~[]; - let mut unused = ~[]; + let mut request = vec!(); + let mut unused = vec!(); let mut delta = 0; for quad in quads_to_check.iter() { @@ -596,7 +596,7 @@ impl<T: Tile> QuadtreeNode<T> { }; delta = delta + c_delta; - request = request + c_request; + request.push_all(c_request.as_slice()); unused.push_all_move(c_unused); } self.tile_mem = (self.tile_mem as int + delta) as uint; @@ -604,10 +604,10 @@ impl<T: Tile> QuadtreeNode<T> { } /// 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) { - Some(tile) => ~[tile], - None => ~[], + Some(tile) => vec!(tile), + None => vec!(), }; for child in self.quadrants.mut_iter() { match *child { diff --git a/src/components/main/constellation.rs b/src/components/main/constellation.rs index f60e3e03c73..4de6ca19820 100644 --- a/src/components/main/constellation.rs +++ b/src/components/main/constellation.rs @@ -44,7 +44,7 @@ pub struct Constellation { pub pipelines: HashMap<PipelineId, Rc<Pipeline>>, navigation_context: NavigationContext, next_pipeline_id: PipelineId, - pending_frames: ~[FrameChange], + pending_frames: Vec<FrameChange>, pending_sizes: HashMap<(PipelineId, SubpageId), Rect<f32>>, pub profiler_chan: ProfilerChan, pub window_size: Size2D<uint>, @@ -55,7 +55,7 @@ pub struct Constellation { struct FrameTree { pub pipeline: Rc<Pipeline>, pub parent: RefCell<Option<Rc<Pipeline>>>, - pub children: RefCell<~[ChildFrameTree]>, + pub children: RefCell<Vec<ChildFrameTree>>, } struct ChildFrameTree { @@ -158,7 +158,7 @@ impl Iterator<Rc<FrameTree>> for FrameTreeIterator { fn next(&mut self) -> Option<Rc<FrameTree>> { if !self.stack.is_empty() { let next = self.stack.pop(); - for cft in next.get_ref().children.borrow().rev_iter() { + for cft in next.get_ref().children.borrow().iter() { self.stack.push(cft.frame_tree.clone()); } Some(next.unwrap()) @@ -177,16 +177,16 @@ struct FrameChange { /// Stores the Id's of the pipelines previous and next in the browser's history struct NavigationContext { - pub previous: ~[Rc<FrameTree>], - pub next: ~[Rc<FrameTree>], + pub previous: Vec<Rc<FrameTree>>, + pub next: Vec<Rc<FrameTree>>, pub current: Option<Rc<FrameTree>>, } impl NavigationContext { fn new() -> NavigationContext { NavigationContext { - previous: ~[], - next: ~[], + previous: vec!(), + next: vec!(), current: None, } } @@ -209,9 +209,9 @@ impl NavigationContext { } /// Loads a new set of page frames, returning all evicted frame trees - fn load(&mut self, frame_tree: Rc<FrameTree>) -> ~[Rc<FrameTree>] { + fn load(&mut self, frame_tree: Rc<FrameTree>) -> Vec<Rc<FrameTree>> { debug!("navigating to {:?}", frame_tree.pipeline.id); - let evicted = replace(&mut self.next, ~[]); + let evicted = replace(&mut self.next, vec!()); if self.current.is_some() { self.previous.push(self.current.take_unwrap()); } @@ -265,7 +265,7 @@ impl Constellation { pipelines: HashMap::new(), navigation_context: NavigationContext::new(), next_pipeline_id: PipelineId(0), - pending_frames: ~[], + pending_frames: vec!(), pending_sizes: HashMap::new(), profiler_chan: profiler_chan, window_size: Size2D(800u, 600u), @@ -410,7 +410,7 @@ impl Constellation { }); idx.map(|idx| { debug!("removing pending frame change for failed pipeline"); - force_pipeline_exit(&self.pending_frames[idx].after.pipeline); + force_pipeline_exit(&self.pending_frames.get(idx).after.pipeline); self.pending_frames.remove(idx) }); if idx.is_none() { @@ -438,7 +438,7 @@ impl Constellation { after: Rc::new(FrameTree { pipeline: pipeline_wrapped.clone(), parent: RefCell::new(None), - children: RefCell::new(~[]), + children: RefCell::new(vec!()), }), navigation_type: constellation_msg::Load, }); @@ -464,7 +464,7 @@ impl Constellation { after: Rc::new(FrameTree { pipeline: pipeline_wrapped.clone(), parent: RefCell::new(None), - children: RefCell::new(~[]), + children: RefCell::new(vec!()), }), navigation_type: constellation_msg::Load, }); @@ -611,7 +611,7 @@ impl Constellation { frame_tree: Rc::new(FrameTree { pipeline: pipeline_wrapped.clone(), parent: RefCell::new(Some(source_pipeline.clone())), - children: RefCell::new(~[]), + children: RefCell::new(vec!()), }), rect: rect, }); @@ -664,7 +664,7 @@ impl Constellation { after: Rc::new(FrameTree { pipeline: pipeline_wrapped.clone(), parent: parent, - children: RefCell::new(~[]), + children: RefCell::new(vec!()), }), navigation_type: constellation_msg::Load, }); @@ -848,7 +848,7 @@ impl Constellation { } } - fn handle_evicted_frames(&mut self, evicted: ~[Rc<FrameTree>]) { + fn handle_evicted_frames(&mut self, evicted: Vec<Rc<FrameTree>>) { for frame_tree in evicted.iter() { if !self.navigation_context.contains(frame_tree.pipeline.id) { self.close_pipelines(frame_tree.clone()); diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index e1fd7adb839..5e80bbcb04d 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -1311,7 +1311,7 @@ impl BlockFlow { pub fn propagate_assigned_width_to_children(&mut self, left_content_edge: Au, content_width: Au, - opt_col_widths: Option<~[Au]>) { + opt_col_widths: Option<Vec<Au>>) { // Keep track of whether floats could impact each child. let mut left_floats_impact_child = self.base.flags.impacted_by_left_floats(); let mut right_floats_impact_child = self.base.flags.impacted_by_right_floats(); @@ -1382,7 +1382,7 @@ impl BlockFlow { propagate_column_widths_to_child(kid, i, content_width, - *col_widths, + col_widths.as_slice(), &mut left_margin_edge) } None => {} @@ -2358,7 +2358,7 @@ fn propagate_column_widths_to_child(kid: &mut Flow, // // FIXME(pcwalton): This seems inefficient. Reference count it instead? let width = if kid.is_table() || kid.is_table_rowgroup() || kid.is_table_row() { - *kid.col_widths() = column_widths.to_owned(); + *kid.col_widths() = column_widths.iter().map(|&x| x).collect(); // Width of kid flow is our content width. content_width diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 41b133243e1..f3544fc4e62 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -94,7 +94,7 @@ pub struct Box { /// New-line chracter(\n)'s positions(relative, not absolute) /// /// FIXME(#2260, pcwalton): This is very inefficient; remove. - pub new_line_pos: ~[uint], + pub new_line_pos: Vec<uint>, } /// Info specific to the kind of box. Keep this enum small. @@ -313,7 +313,7 @@ impl Box { border_padding: Zero::zero(), margin: Zero::zero(), specific: constructor.build_specific_box_info_for_node(node), - new_line_pos: ~[], + new_line_pos: vec!(), } } @@ -326,7 +326,7 @@ impl Box { border_padding: Zero::zero(), margin: Zero::zero(), specific: specific, - new_line_pos: ~[], + new_line_pos: vec!(), } } @@ -350,7 +350,7 @@ impl Box { border_padding: Zero::zero(), margin: Zero::zero(), specific: specific, - new_line_pos: ~[], + new_line_pos: vec!(), } } @@ -366,7 +366,7 @@ impl Box { border_padding: Zero::zero(), margin: Zero::zero(), specific: specific, - new_line_pos: ~[], + new_line_pos: vec!(), } } @@ -1114,7 +1114,7 @@ impl Box { let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range); let new_metrics = new_text_box_info.run.metrics_for_range(&left_range); let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info)); - new_box.new_line_pos = ~[]; + new_box.new_line_pos = vec!(); Some(new_box) }; diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 1191dd1f31b..42a3d87ee0e 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -125,7 +125,7 @@ pub struct InlineBoxesConstructionResult { /// Any {ib} splits that we're bubbling up. /// /// TODO(pcwalton): Small vector optimization. - pub splits: Option<~[InlineBlockSplit]>, + pub splits: Option<Vec<InlineBlockSplit>>, /// Any boxes that succeed the {ib} splits. pub boxes: InlineBoxes, @@ -280,6 +280,58 @@ 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. @@ -371,7 +423,7 @@ impl<'a> FlowConstructor<'a> { fn flush_inline_boxes_to_flow_or_list(&mut self, box_accumulator: InlineBoxAccumulator, flow: &mut ~Flow:Share, - flow_list: &mut ~[~Flow:Share], + flow_list: &mut Vec<~Flow:Share>, whitespace_stripping: WhitespaceStrippingMode, node: &ThreadSafeLayoutNode) { let mut boxes = box_accumulator.finish(); @@ -411,7 +463,7 @@ impl<'a> FlowConstructor<'a> { fn build_block_flow_using_children_construction_result(&mut self, flow: &mut ~Flow:Share, consecutive_siblings: - &mut ~[~Flow:Share], + &mut Vec<~Flow:Share>, node: &ThreadSafeLayoutNode, kid: ThreadSafeLayoutNode, inline_box_accumulator: @@ -450,7 +502,7 @@ impl<'a> FlowConstructor<'a> { whitespace_stripping, node); if !consecutive_siblings.is_empty() { - let consecutive_siblings = mem::replace(consecutive_siblings, ~[]); + let consecutive_siblings = mem::replace(consecutive_siblings, vec!()); self.generate_anonymous_missing_child(consecutive_siblings, flow, node); @@ -536,7 +588,7 @@ impl<'a> FlowConstructor<'a> { -> ConstructionResult { // Gather up boxes for the inline flows we might need to create. let mut inline_box_accumulator = InlineBoxAccumulator::new(); - let mut consecutive_siblings = ~[]; + let mut consecutive_siblings = vec!(); let mut first_box = true; // List of absolute descendants, in tree order. @@ -606,7 +658,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 = None; + let mut opt_inline_block_splits: Option<Vec<InlineBlockSplit>> = None; let mut box_accumulator = InlineBoxAccumulator::from_inline_node(node); let mut abs_descendants = Descendants::new(); @@ -755,11 +807,11 @@ impl<'a> FlowConstructor<'a> { /// Generates an anonymous table flow according to CSS 2.1 § 17.2.1, step 2. /// If necessary, generate recursively another anonymous table flow. fn generate_anonymous_missing_child(&mut self, - child_flows: ~[~Flow:Share], + child_flows: Vec<~Flow:Share>, flow: &mut ~Flow:Share, node: &ThreadSafeLayoutNode) { let mut anonymous_flow = flow.generate_missing_child_flow(node); - let mut consecutive_siblings = ~[]; + let mut consecutive_siblings = vec!(); for kid_flow in child_flows.move_iter() { if anonymous_flow.need_anonymous_flow(kid_flow) { consecutive_siblings.push(kid_flow); @@ -767,7 +819,7 @@ impl<'a> FlowConstructor<'a> { } if !consecutive_siblings.is_empty() { self.generate_anonymous_missing_child(consecutive_siblings, &mut anonymous_flow, node); - consecutive_siblings = ~[]; + consecutive_siblings = vec!(); } anonymous_flow.add_new_child(kid_flow); } @@ -879,7 +931,7 @@ impl<'a> FlowConstructor<'a> { fn build_flow_for_table_colgroup(&mut self, node: &ThreadSafeLayoutNode) -> ConstructionResult { let box_ = Box::new_from_specific_info(node, TableColumnBox(TableColumnBoxInfo::new(node))); - let mut col_boxes = ~[]; + let mut col_boxes = vec!(); for kid in node.children() { // CSS 2.1 § 17.2.1. Treat all non-column child boxes of `table-column-group` // as `display: none`. diff --git a/src/components/main/layout/floats.rs b/src/components/main/layout/floats.rs index fc1d6bafe89..4f58da33e33 100644 --- a/src/components/main/layout/floats.rs +++ b/src/components/main/layout/floats.rs @@ -50,7 +50,7 @@ struct Float { #[deriving(Clone)] struct FloatList { /// Information about each of the floats here. - floats: ~[Float], + floats: Vec<Float>, /// Cached copy of the maximum top offset of the float. max_top: Au, } @@ -58,7 +58,7 @@ struct FloatList { impl FloatList { fn new() -> FloatList { FloatList { - floats: ~[], + floats: vec!(), max_top: Au(0), } } diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index f734fe24058..f599e5f7225 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -28,7 +28,6 @@ use css::node_style::StyledNode; use layout::block::BlockFlow; use layout::box_::{Box, TableRowBox, TableCellBox}; -use layout::construct::OptVector; use layout::context::LayoutContext; use layout::floats::Floats; use layout::flow_list::{FlowList, Link, Rawlink, FlowListIterator, MutFlowListIterator}; @@ -129,19 +128,19 @@ pub trait Flow { /// If this is a table row or table rowgroup or table flow, returns column widths. /// Fails otherwise. - fn col_widths<'a>(&'a mut self) -> &'a mut ~[Au] { + fn col_widths<'a>(&'a mut self) -> &'a mut Vec<Au> { fail!("called col_widths() on an other flow than table-row/table-rowgroup/table") } /// If this is a table row flow or table rowgroup flow or table flow, returns column min widths. /// Fails otherwise. - fn col_min_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_min_widths<'a>(&'a self) -> &'a Vec<Au> { fail!("called col_min_widths() on an other flow than table-row/table-rowgroup/table") } /// If this is a table row flow or table rowgroup flow or table flow, returns column min widths. /// Fails otherwise. - fn col_pref_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_pref_widths<'a>(&'a self) -> &'a Vec<Au> { fail!("called col_pref_widths() on an other flow than table-row/table-rowgroup/table") } diff --git a/src/components/main/layout/table.rs b/src/components/main/layout/table.rs index 67ac6bd34b5..ce608ad569a 100644 --- a/src/components/main/layout/table.rs +++ b/src/components/main/layout/table.rs @@ -25,13 +25,13 @@ pub struct TableFlow { pub block_flow: BlockFlow, /// Column widths - pub col_widths: ~[Au], + pub col_widths: Vec<Au>, /// Column min widths. - pub col_min_widths: ~[Au], + pub col_min_widths: Vec<Au>, /// Column pref widths. - pub col_pref_widths: ~[Au], + pub col_pref_widths: Vec<Au>, /// Table-layout property pub table_layout: TableLayout, @@ -50,9 +50,9 @@ impl TableFlow { }; TableFlow { block_flow: block_flow, - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), table_layout: table_layout } } @@ -69,9 +69,9 @@ impl TableFlow { }; TableFlow { block_flow: block_flow, - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), table_layout: table_layout } } @@ -89,23 +89,23 @@ impl TableFlow { }; TableFlow { block_flow: block_flow, - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), table_layout: table_layout } } pub fn teardown(&mut self) { self.block_flow.teardown(); - self.col_widths = ~[]; - self.col_min_widths = ~[]; - self.col_pref_widths = ~[]; + self.col_widths = vec!(); + self.col_min_widths = vec!(); + self.col_pref_widths = vec!(); } /// Update the corresponding value of self_widths if a value of kid_widths has larger value /// than one of self_widths. - pub fn update_col_widths(self_widths: &mut ~[Au], kid_widths: &~[Au]) -> Au { + pub fn update_col_widths(self_widths: &mut Vec<Au>, kid_widths: &Vec<Au>) -> Au { let mut sum_widths = Au(0); let mut kid_widths_it = kid_widths.iter(); for self_width in self_widths.mut_iter() { @@ -152,15 +152,15 @@ impl Flow for TableFlow { &mut self.block_flow } - fn col_widths<'a>(&'a mut self) -> &'a mut ~[Au] { + fn col_widths<'a>(&'a mut self) -> &'a mut Vec<Au> { &mut self.col_widths } - fn col_min_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_min_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_min_widths } - fn col_pref_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_pref_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_pref_widths } @@ -177,7 +177,7 @@ impl Flow for TableFlow { assert!(kid.is_proper_table_child()); if kid.is_table_colgroup() { - self.col_widths.push_all(kid.as_table_colgroup().widths); + self.col_widths.push_all(kid.as_table_colgroup().widths.as_slice()); self.col_min_widths = self.col_widths.clone(); self.col_pref_widths = self.col_widths.clone(); } else if kid.is_table_rowgroup() || kid.is_table_row() { @@ -207,7 +207,7 @@ impl Flow for TableFlow { debug!("table until the previous row has {} column(s) and this row has {} column(s)", num_cols, num_child_cols); for i in range(num_cols, num_child_cols) { - self.col_widths.push( kid_col_widths[i] ); + self.col_widths.push( *kid_col_widths.get(i) ); } }, AutoLayout => { @@ -221,9 +221,9 @@ impl Flow for TableFlow { num_cols, num_child_cols); for i in range(num_cols, num_child_cols) { self.col_widths.push(Au::new(0)); - let new_kid_min = kid.col_min_widths()[i]; + let new_kid_min = *kid.col_min_widths().get(i); self.col_min_widths.push( new_kid_min ); - let new_kid_pref = kid.col_pref_widths()[i]; + let new_kid_pref = *kid.col_pref_widths().get(i); self.col_pref_widths.push( new_kid_pref ); min_width = min_width + new_kid_min; pref_width = pref_width + new_kid_pref; diff --git a/src/components/main/layout/table_colgroup.rs b/src/components/main/layout/table_colgroup.rs index 099745fc8ed..2edcab3cd0c 100644 --- a/src/components/main/layout/table_colgroup.rs +++ b/src/components/main/layout/table_colgroup.rs @@ -20,21 +20,21 @@ pub struct TableColGroupFlow { pub box_: Option<Box>, /// The table column boxes - pub cols: ~[Box], + pub cols: Vec<Box>, /// The specified widths of table columns - pub widths: ~[Au], + pub widths: Vec<Au>, } impl TableColGroupFlow { pub fn from_node_and_boxes(node: &ThreadSafeLayoutNode, box_: Box, - boxes: ~[Box]) -> TableColGroupFlow { + boxes: Vec<Box>) -> TableColGroupFlow { TableColGroupFlow { base: BaseFlow::new((*node).clone()), box_: Some(box_), cols: boxes, - widths: ~[], + widths: vec!(), } } @@ -43,8 +43,8 @@ impl TableColGroupFlow { box_.teardown(); } self.box_ = None; - self.cols = ~[]; - self.widths = ~[]; + self.cols = vec!(); + self.widths = vec!(); } } diff --git a/src/components/main/layout/table_row.rs b/src/components/main/layout/table_row.rs index 9665a7171d5..4560526ef35 100644 --- a/src/components/main/layout/table_row.rs +++ b/src/components/main/layout/table_row.rs @@ -23,13 +23,13 @@ pub struct TableRowFlow { pub block_flow: BlockFlow, /// Column widths. - pub col_widths: ~[Au], + pub col_widths: Vec<Au>, /// Column min widths. - pub col_min_widths: ~[Au], + pub col_min_widths: Vec<Au>, /// Column pref widths. - pub col_pref_widths: ~[Au], + pub col_pref_widths: Vec<Au>, } impl TableRowFlow { @@ -38,9 +38,9 @@ impl TableRowFlow { -> TableRowFlow { TableRowFlow { block_flow: BlockFlow::from_node_and_box(node, box_), - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), } } @@ -49,17 +49,17 @@ impl TableRowFlow { -> TableRowFlow { TableRowFlow { block_flow: BlockFlow::from_node(constructor, node), - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), } } pub fn teardown(&mut self) { self.block_flow.teardown(); - self.col_widths = ~[]; - self.col_min_widths = ~[]; - self.col_pref_widths = ~[]; + self.col_widths = vec!(); + self.col_min_widths = vec!(); + self.col_pref_widths = vec!(); } pub fn box_<'a>(&'a mut self) -> &'a Box { @@ -151,15 +151,15 @@ impl Flow for TableRowFlow { &mut self.block_flow } - fn col_widths<'a>(&'a mut self) -> &'a mut ~[Au] { + fn col_widths<'a>(&'a mut self) -> &'a mut Vec<Au> { &mut self.col_widths } - fn col_min_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_min_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_min_widths } - fn col_pref_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_pref_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_pref_widths } diff --git a/src/components/main/layout/table_rowgroup.rs b/src/components/main/layout/table_rowgroup.rs index 43e7008c649..ca3bf8ca4b5 100644 --- a/src/components/main/layout/table_rowgroup.rs +++ b/src/components/main/layout/table_rowgroup.rs @@ -22,13 +22,13 @@ pub struct TableRowGroupFlow { pub block_flow: BlockFlow, /// Column widths - pub col_widths: ~[Au], + pub col_widths: Vec<Au>, /// Column min widths. - pub col_min_widths: ~[Au], + pub col_min_widths: Vec<Au>, /// Column pref widths. - pub col_pref_widths: ~[Au], + pub col_pref_widths: Vec<Au>, } impl TableRowGroupFlow { @@ -37,9 +37,9 @@ impl TableRowGroupFlow { -> TableRowGroupFlow { TableRowGroupFlow { block_flow: BlockFlow::from_node_and_box(node, box_), - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), } } @@ -48,17 +48,17 @@ impl TableRowGroupFlow { -> TableRowGroupFlow { TableRowGroupFlow { block_flow: BlockFlow::from_node(constructor, node), - col_widths: ~[], - col_min_widths: ~[], - col_pref_widths: ~[], + col_widths: vec!(), + col_min_widths: vec!(), + col_pref_widths: vec!(), } } pub fn teardown(&mut self) { self.block_flow.teardown(); - self.col_widths = ~[]; - self.col_min_widths = ~[]; - self.col_pref_widths = ~[]; + self.col_widths = vec!(); + self.col_min_widths = vec!(); + self.col_pref_widths = vec!(); } pub fn box_<'a>(&'a mut self) -> &'a Box { @@ -118,15 +118,15 @@ impl Flow for TableRowGroupFlow { &mut self.block_flow } - fn col_widths<'a>(&'a mut self) -> &'a mut ~[Au] { + fn col_widths<'a>(&'a mut self) -> &'a mut Vec<Au> { &mut self.col_widths } - fn col_min_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_min_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_min_widths } - fn col_pref_widths<'a>(&'a self) -> &'a ~[Au] { + fn col_pref_widths<'a>(&'a self) -> &'a Vec<Au> { &self.col_pref_widths } @@ -162,10 +162,10 @@ impl Flow for TableRowGroupFlow { let num_child_cols = kid.col_min_widths().len(); for i in range(num_cols, num_child_cols) { self.col_widths.push(Au::new(0)); - let new_kid_min = kid.col_min_widths()[i]; - self.col_min_widths.push(kid.col_min_widths()[i]); - let new_kid_pref = kid.col_pref_widths()[i]; - self.col_pref_widths.push(kid.col_pref_widths()[i]); + let new_kid_min = *kid.col_min_widths().get(i); + self.col_min_widths.push(*kid.col_min_widths().get(i)); + let new_kid_pref = *kid.col_pref_widths().get(i); + self.col_pref_widths.push(*kid.col_pref_widths().get(i)); min_width = min_width + new_kid_min; pref_width = pref_width + new_kid_pref; } diff --git a/src/components/main/layout/table_wrapper.rs b/src/components/main/layout/table_wrapper.rs index 6ae2dd350c2..bdcc501703d 100644 --- a/src/components/main/layout/table_wrapper.rs +++ b/src/components/main/layout/table_wrapper.rs @@ -28,7 +28,7 @@ pub struct TableWrapperFlow { pub block_flow: BlockFlow, /// Column widths - pub col_widths: ~[Au], + pub col_widths: Vec<Au>, /// Table-layout property pub table_layout: TableLayout, @@ -47,7 +47,7 @@ impl TableWrapperFlow { }; TableWrapperFlow { block_flow: block_flow, - col_widths: ~[], + col_widths: vec!(), table_layout: table_layout } } @@ -64,7 +64,7 @@ impl TableWrapperFlow { }; TableWrapperFlow { block_flow: block_flow, - col_widths: ~[], + col_widths: vec!(), table_layout: table_layout } } @@ -82,7 +82,7 @@ impl TableWrapperFlow { }; TableWrapperFlow { block_flow: block_flow, - col_widths: ~[], + col_widths: vec!(), table_layout: table_layout } } @@ -93,7 +93,7 @@ impl TableWrapperFlow { pub fn teardown(&mut self) { self.block_flow.teardown(); - self.col_widths = ~[]; + self.col_widths = vec!(); } /// Assign height for table-wrapper flow. @@ -137,7 +137,7 @@ impl Flow for TableWrapperFlow { assert!(kid.is_table_caption() || kid.is_table()); if kid.is_table() { - self.col_widths.push_all(kid.as_table().col_widths); + self.col_widths.push_all(kid.as_table().col_widths.as_slice()); } } @@ -257,8 +257,8 @@ impl TableWrapper { let mut cap_min = Au(0); let mut cols_min = Au(0); let mut cols_max = Au(0); - let mut col_min_widths = &~[]; - let mut col_pref_widths = &~[]; + let mut col_min_widths = &vec!(); + let mut col_pref_widths = &vec!(); for kid in table_wrapper.block_flow.base.child_iter() { if kid.is_table_caption() { cap_min = kid.as_block().base.intrinsic_widths.minimum_width; diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index 1ae5a0cbee2..2b048bf60c8 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -16,13 +16,12 @@ use servo_util::geometry::Au; use servo_util::range::Range; use servo_util::smallvec::{SmallVec, SmallVec0}; use std::mem; -use std::slice; use style::ComputedValues; use style::computed_values::{font_family, line_height, white_space}; use sync::Arc; struct NewLinePositions { - new_line_pos: ~[uint], + new_line_pos: Vec<uint>, } // A helper function. @@ -138,7 +137,8 @@ impl TextRunScanner { white_space::pre => CompressNone, }; - let mut new_line_pos = ~[]; + let mut new_line_pos = vec!(); + let (transformed_text, whitespace) = transform_text(*text, compression, last_whitespace, @@ -181,11 +181,11 @@ impl TextRunScanner { white_space::pre => CompressNone, }; - let mut new_line_positions: ~[NewLinePositions] = ~[]; + let mut new_line_positions: Vec<NewLinePositions> = vec!(); // First, transform/compress text of all the nodes. let mut last_whitespace_in_clump = new_whitespace; - let transformed_strs: ~[~str] = slice::from_fn(self.clump.length(), |i| { + let transformed_strs: Vec<~str> = Vec::from_fn(self.clump.length(), |i| { // TODO(#113): We should be passing the compression context between calls to // `transform_text`, so that boxes starting and/or ending with whitespace can // be compressed correctly with respect to the text run. @@ -195,7 +195,7 @@ impl TextRunScanner { _ => fail!("Expected an unscanned text box!"), }; - let mut new_line_pos = ~[]; + let mut new_line_pos = vec!(); let (new_str, new_whitespace) = transform_text(*in_box, compression, @@ -211,12 +211,12 @@ impl TextRunScanner { // Next, concatenate all of the transformed strings together, saving the new // character indices. let mut run_str: ~str = "".to_owned(); - let mut new_ranges: ~[Range] = ~[]; + let mut new_ranges: Vec<Range> = vec!(); let mut char_total = 0; for i in range(0, transformed_strs.len()) { - let added_chars = transformed_strs[i].char_len(); + let added_chars = transformed_strs.get(i).char_len(); new_ranges.push(Range::new(char_total, added_chars)); - run_str.push_str(transformed_strs[i]); + run_str.push_str(*transformed_strs.get(i)); char_total += added_chars; } @@ -225,7 +225,7 @@ impl TextRunScanner { // sequence. If no clump takes ownership, however, it will leak. let clump = self.clump; let run = if clump.length() != 0 && run_str.len() > 0 { - Some(Arc::new(~TextRun::new(&mut *fontgroup.borrow().fonts[0].borrow_mut(), + Some(Arc::new(~TextRun::new(&mut *fontgroup.borrow().fonts.get(0).borrow_mut(), run_str.clone(), decoration))) } else { None @@ -235,7 +235,7 @@ impl TextRunScanner { debug!("TextRunScanner: pushing box(es) in range: {}", self.clump); for i in clump.eachi() { let logical_offset = i - self.clump.begin(); - let range = new_ranges[logical_offset]; + let range = new_ranges.get(logical_offset); if range.length() == 0 { debug!("Elided an `UnscannedTextbox` because it was zero-length after \ compression; {:s}", @@ -243,11 +243,11 @@ impl TextRunScanner { continue } - let new_text_box_info = ScannedTextBoxInfo::new(run.get_ref().clone(), range); - let new_metrics = new_text_box_info.run.metrics_for_range(&range); + let new_text_box_info = ScannedTextBoxInfo::new(run.get_ref().clone(), *range); + let new_metrics = new_text_box_info.run.metrics_for_range(range); let mut new_box = in_boxes[i].transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info)); - new_box.new_line_pos = new_line_positions[logical_offset].new_line_pos.clone(); + new_box.new_line_pos = new_line_positions.get(logical_offset).new_line_pos.clone(); out_boxes.push(new_box) } } @@ -267,7 +267,7 @@ impl TextRunScanner { pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: &FontStyle) -> FontMetrics { let fontgroup = font_context.get_resolved_font_for_style(font_style); - fontgroup.borrow().fonts[0].borrow().metrics.clone() + fontgroup.borrow().fonts.get(0).borrow().metrics.clone() } /// Converts a computed style to a font style used for rendering. diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index aa8600db82e..0b2bb795545 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -204,7 +204,7 @@ impl<'ln> LayoutNode<'ln> { /// /// FIXME(pcwalton): Terribly inefficient. We should use parallelism. pub fn traverse_preorder(&self) -> LayoutTreeIterator<'ln> { - let mut nodes = ~[]; + let mut nodes = vec!(); gather_layout_nodes(self, &mut nodes, false); LayoutTreeIterator::new(nodes) } @@ -301,12 +301,12 @@ impl<'a> Iterator<LayoutNode<'a>> for LayoutNodeChildrenIterator<'a> { // // FIXME(pcwalton): Parallelism! Eventually this should just be nuked. pub struct LayoutTreeIterator<'a> { - nodes: ~[LayoutNode<'a>], + nodes: Vec<LayoutNode<'a>>, index: uint, } impl<'a> LayoutTreeIterator<'a> { - fn new(nodes: ~[LayoutNode<'a>]) -> LayoutTreeIterator<'a> { + fn new(nodes: Vec<LayoutNode<'a>>) -> LayoutTreeIterator<'a> { LayoutTreeIterator { nodes: nodes, index: 0, @@ -319,7 +319,7 @@ impl<'a> Iterator<LayoutNode<'a>> for LayoutTreeIterator<'a> { if self.index >= self.nodes.len() { None } else { - let v = self.nodes[self.index].clone(); + let v = self.nodes.get(self.index).clone(); self.index += 1; Some(v) } @@ -327,7 +327,7 @@ impl<'a> Iterator<LayoutNode<'a>> for LayoutTreeIterator<'a> { } /// FIXME(pcwalton): This is super inefficient. -fn gather_layout_nodes<'a>(cur: &LayoutNode<'a>, refs: &mut ~[LayoutNode<'a>], postorder: bool) { +fn gather_layout_nodes<'a>(cur: &LayoutNode<'a>, refs: &mut Vec<LayoutNode<'a>>, postorder: bool) { if !postorder { refs.push(cur.clone()); } diff --git a/src/components/main/platform/common/glfw_windowing.rs b/src/components/main/platform/common/glfw_windowing.rs index 5c99921ac90..d200e5c9443 100644 --- a/src/components/main/platform/common/glfw_windowing.rs +++ b/src/components/main/platform/common/glfw_windowing.rs @@ -88,7 +88,7 @@ pub struct Window { pub glfw_window: glfw::Window, pub events: Receiver<(f64, glfw::WindowEvent)>, - pub event_queue: RefCell<~[WindowEvent]>, + pub event_queue: RefCell<Vec<WindowEvent>>, pub drag_origin: Point2D<c_int>, @@ -116,7 +116,7 @@ impl WindowMethods<Application> for Window { glfw_window: glfw_window, events: events, - event_queue: RefCell::new(~[]), + event_queue: RefCell::new(vec!()), drag_origin: Point2D(0 as c_int, 0), diff --git a/src/components/main/platform/common/glut_windowing.rs b/src/components/main/platform/common/glut_windowing.rs index 00e3128e81a..09894d249d9 100644 --- a/src/components/main/platform/common/glut_windowing.rs +++ b/src/components/main/platform/common/glut_windowing.rs @@ -47,7 +47,7 @@ impl Drop for Application { pub struct Window { pub glut_window: glut::Window, - pub event_queue: RefCell<~[WindowEvent]>, + pub event_queue: RefCell<Vec<WindowEvent>>, pub drag_origin: Point2D<c_int>, @@ -70,7 +70,7 @@ impl WindowMethods<Application> for Window { let window = Window { glut_window: glut_window, - event_queue: RefCell::new(~[]), + event_queue: RefCell::new(vec!()), drag_origin: Point2D(0 as c_int, 0), diff --git a/src/components/main/servo.rs b/src/components/main/servo.rs index 99df8e079ba..d07f24f15d2 100755 --- a/src/components/main/servo.rs +++ b/src/components/main/servo.rs @@ -137,7 +137,7 @@ fn start(argc: int, argv: **u8) -> int { #[no_mangle] pub extern "C" fn android_start(argc: int, argv: **u8) -> int { native::start(argc, argv, proc() { - let mut args:~[~str] = ~[]; + let mut args: Vec<~str> = vec!(); for i in range(0u, argc as uint) { unsafe { args.push(str::raw::from_c_str(*argv.offset(i as int) as *i8)); @@ -193,7 +193,7 @@ fn run(opts: opts::Opts) { // As a hack for easier command-line testing, // assume that data URLs are not URL-encoded. Url::new("data".to_owned(), None, "".to_owned(), None, - filename.slice_from(5).to_owned(), Vec::new(), None) + filename.slice_from(5).to_owned(), vec!(), None) } else { parse_url(*filename, None) }; diff --git a/src/components/msg/compositor_msg.rs b/src/components/msg/compositor_msg.rs index f6058c16e6a..1b71e203596 100644 --- a/src/components/msg/compositor_msg.rs +++ b/src/components/msg/compositor_msg.rs @@ -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 /// buffers. pub struct LayerBufferSet { - pub buffers: ~[~LayerBuffer] + pub buffers: Vec<~LayerBuffer> } impl LayerBufferSet { diff --git a/src/components/net/file_loader.rs b/src/components/net/file_loader.rs index 45d46e53840..57f356864a7 100644 --- a/src/components/net/file_loader.rs +++ b/src/components/net/file_loader.rs @@ -14,7 +14,7 @@ static READ_SIZE: uint = 1; fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>) -> Result<(), ()> { loop { - let mut buf = Vec::new(); + let mut buf = vec!(); match reader.push_exact(&mut buf, READ_SIZE) { Ok(_) => progress_chan.send(Payload(buf)), Err(e) => match e.kind { diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 68a8e7d4981..a88c5e6da3d 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -96,12 +96,12 @@ pub fn start_sending(start_chan: Sender<LoadResponse>, /// Convenience function for synchronously loading a whole resource. pub fn load_whole_resource(resource_task: &ResourceTask, url: Url) - -> Result<(Metadata, ~[u8]), ()> { + -> Result<(Metadata, Vec<u8>), ()> { let (start_chan, start_port) = channel(); resource_task.send(Load(url, start_chan)); let response = start_port.recv(); - let mut buf = ~[]; + let mut buf = vec!(); loop { match response.progress_port.recv() { Payload(data) => buf.push_all(data.as_slice()), diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 8cebc7326e6..1254b11538c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -140,7 +140,7 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>, } Ok((metadata, bytes)) => { result_vec.push(JSFile { - data: str::from_utf8(bytes).unwrap().to_owned(), + data: str::from_utf8(bytes.as_slice()).unwrap().to_owned(), url: metadata.final_url, }); } diff --git a/src/components/style/media_queries.rs b/src/components/style/media_queries.rs index 5c8bbb80cf2..5ead74f3914 100644 --- a/src/components/style/media_queries.rs +++ b/src/components/style/media_queries.rs @@ -14,14 +14,14 @@ use url::Url; pub struct MediaRule { pub media_queries: MediaQueryList, - pub rules: ~[CSSRule], + pub rules: Vec<CSSRule>, } pub struct MediaQueryList { // "not all" is omitted from the list. // An empty list never matches. - media_queries: ~[MediaQuery] + media_queries: Vec<MediaQuery> } // For now, this is a "Level 2 MQ", ie. a media type. @@ -48,7 +48,7 @@ pub struct Device { } -pub fn parse_media_rule(rule: AtRule, parent_rules: &mut ~[CSSRule], +pub fn parse_media_rule(rule: AtRule, parent_rules: &mut Vec<CSSRule>, namespaces: &NamespaceMap, base_url: &Url) { let media_queries = parse_media_query_list(rule.prelude); let block = match rule.block { @@ -58,7 +58,7 @@ pub fn parse_media_rule(rule: AtRule, parent_rules: &mut ~[CSSRule], return } }; - let mut rules = ~[]; + let mut rules = vec!(); for rule in ErrorLoggerIterator(parse_rule_list(block.move_iter())) { match rule { QualifiedRule(rule) => parse_style_rule(rule, &mut rules, namespaces, base_url), @@ -77,9 +77,9 @@ pub fn parse_media_query_list(input: &[ComponentValue]) -> MediaQueryList { let iter = &mut input.skip_whitespace(); let mut next = iter.next(); if next.is_none() { - return MediaQueryList{ media_queries: ~[MediaQuery{media_type: All}] } + return MediaQueryList{ media_queries: vec!(MediaQuery{media_type: All}) } } - let mut queries = ~[]; + let mut queries = vec!(); loop { let mq = match next { Some(&Ident(ref value)) => { diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako index 682c373c7ab..8f3fe933daa 100644 --- a/src/components/style/properties.rs.mako +++ b/src/components/style/properties.rs.mako @@ -527,7 +527,7 @@ pub mod longhands { pub enum T { normal, none, - Content(~[Content]), + Content(Vec<Content>), } } pub type SpecifiedValue = computed_value::T; @@ -549,7 +549,7 @@ pub mod longhands { }, _ => () } - let mut content = ~[]; + let mut content = vec!(); for component_value in input.skip_whitespace() { match component_value { &String(ref value) @@ -705,10 +705,10 @@ pub mod longhands { // Fantasy, // Monospace, } - pub type T = ~[FontFamily]; + pub type T = Vec<FontFamily>; } pub type SpecifiedValue = computed_value::T; - #[inline] pub fn get_initial_value() -> computed_value::T { ~[FamilyName(~"serif")] } + #[inline] pub fn get_initial_value() -> computed_value::T { vec!(FamilyName(~"serif")) } /// <familiy-name># /// <familiy-name> = <string> | [ <ident>+ ] /// TODO: <generic-familiy> @@ -716,7 +716,7 @@ pub mod longhands { from_iter(input.skip_whitespace()) } pub fn from_iter<'a>(mut iter: SkipWhitespaceIterator<'a>) -> Option<SpecifiedValue> { - let mut result = ~[]; + let mut result = vec!(); macro_rules! add( ($value: expr, $b: expr) => { { @@ -743,7 +743,7 @@ pub mod longhands { // "fantasy" => add!(Fantasy, break 'outer), // "monospace" => add!(Monospace, break 'outer), _ => { - let mut idents = ~[value.as_slice()]; + let mut idents = vec!(value.as_slice()); loop { match iter.next() { Some(&Ident(ref value)) => idents.push(value.as_slice()), @@ -1332,8 +1332,8 @@ pub mod shorthands { pub struct PropertyDeclarationBlock { - pub important: Arc<~[PropertyDeclaration]>, - pub normal: Arc<~[PropertyDeclaration]>, + pub important: Arc<Vec<PropertyDeclaration>>, + pub normal: Arc<Vec<PropertyDeclaration>>, } impl<E, S: Encoder<E>> Encodable<S, E> for PropertyDeclarationBlock { @@ -1349,8 +1349,8 @@ pub fn parse_style_attribute(input: &str, base_url: &Url) -> PropertyDeclaration pub fn parse_property_declaration_list<I: Iterator<Node>>(input: I, base_url: &Url) -> PropertyDeclarationBlock { - let mut important = ~[]; - let mut normal = ~[]; + let mut important = vec!(); + let mut normal = vec!(); for item in ErrorLoggerIterator(parse_declaration_list(input)) { match item { DeclAtRule(rule) => log_css_error( @@ -1418,7 +1418,7 @@ pub enum PropertyDeclarationParseResult { impl PropertyDeclaration { pub fn parse(name: &str, value: &[ComponentValue], - result_list: &mut ~[PropertyDeclaration], + result_list: &mut Vec<PropertyDeclaration>, base_url: &Url) -> PropertyDeclarationParseResult { // FIXME: local variable to work around Rust #10683 let name_lower = name.to_ascii_lower(); diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs index f728b3dd7ed..c45d56acf40 100644 --- a/src/components/style/selector_matching.rs +++ b/src/components/style/selector_matching.rs @@ -481,14 +481,14 @@ struct Rule { /// we can sort them. #[deriving(Clone)] pub struct MatchedProperty { - pub declarations: Arc<~[PropertyDeclaration]>, + pub declarations: Arc<Vec<PropertyDeclaration>>, source_order: uint, specificity: u32, } impl MatchedProperty { #[inline] - pub fn from_declarations(declarations: Arc<~[PropertyDeclaration]>) -> MatchedProperty { + pub fn from_declarations(declarations: Arc<Vec<PropertyDeclaration>>) -> MatchedProperty { MatchedProperty { declarations: declarations, source_order: 0, @@ -960,7 +960,7 @@ mod tests { selector: s.compound_selectors.clone(), property: MatchedProperty { specificity: s.specificity, - declarations: Arc::new(~[]), + declarations: Arc::new(vec!()), source_order: i, } } diff --git a/src/components/style/selectors.rs b/src/components/style/selectors.rs index 4d9994e9b56..b7d9d986ce5 100644 --- a/src/components/style/selectors.rs +++ b/src/components/style/selectors.rs @@ -42,7 +42,7 @@ pub enum PseudoElement { #[deriving(Eq, Clone)] pub struct CompoundSelector { - pub simple_selectors: ~[SimpleSelector], + pub simple_selectors: Vec<SimpleSelector>, pub next: Option<(~CompoundSelector, Combinator)>, // c.next is left of c } @@ -71,7 +71,7 @@ pub enum SimpleSelector { AttrSuffixMatch(AttrSelector, ~str), // [foo$=bar] // Pseudo-classes - Negation(~[SimpleSelector]), + Negation(Vec<SimpleSelector>), AnyLink, Link, Visited, @@ -112,13 +112,13 @@ type Iter = iter::Peekable<ComponentValue, slice::MoveItems<ComponentValue>>; /// /// Return the Selectors or None if there is an invalid selector. pub fn parse_selector_list(input: ~[ComponentValue], namespaces: &NamespaceMap) - -> Option<~[Selector]> { + -> Option<Vec<Selector>> { let iter = &mut input.move_iter().peekable(); let first = match parse_selector(iter, namespaces) { None => return None, Some(result) => result }; - let mut results = ~[first]; + let mut results = vec!(first); loop { skip_whitespace(iter); @@ -197,13 +197,13 @@ fn compute_specificity(mut selector: &CompoundSelector, }; if pseudo_element.is_some() { specificity.element_selectors += 1 } - simple_selectors_specificity(selector.simple_selectors, &mut specificity); + simple_selectors_specificity(selector.simple_selectors.as_slice(), &mut specificity); loop { match selector.next { None => break, Some((ref next_selector, _)) => { selector = &**next_selector; - simple_selectors_specificity(selector.simple_selectors, &mut specificity) + simple_selectors_specificity(selector.simple_selectors.as_slice(), &mut specificity) } } } @@ -244,11 +244,11 @@ fn compute_specificity(mut selector: &CompoundSelector, /// /// None means invalid selector fn parse_simple_selectors(iter: &mut Iter, namespaces: &NamespaceMap) - -> Option<(~[SimpleSelector], Option<PseudoElement>)> { + -> Option<(Vec<SimpleSelector>, Option<PseudoElement>)> { let mut empty = true; let mut simple_selectors = match parse_type_selector(iter, namespaces) { InvalidTypeSelector => return None, - NotATypeSelector => ~[], + NotATypeSelector => vec!(), TypeSelector(s) => { empty = false; s } }; @@ -269,7 +269,7 @@ fn parse_simple_selectors(iter: &mut Iter, namespaces: &NamespaceMap) enum TypeSelectorParseResult { InvalidTypeSelector, NotATypeSelector, - TypeSelector(~[SimpleSelector]), // Length 0 (*|*), 1 (*|E or ns|*) or 2 (|E or ns|E) + TypeSelector(Vec<SimpleSelector>), // Length 0 (*|*), 1 (*|E or ns|*) or 2 (|E or ns|E) } fn parse_type_selector(iter: &mut Iter, namespaces: &NamespaceMap) @@ -279,7 +279,7 @@ fn parse_type_selector(iter: &mut Iter, namespaces: &NamespaceMap) InvalidQualifiedName => InvalidTypeSelector, NotAQualifiedName => NotATypeSelector, QualifiedName(namespace, local_name) => { - let mut simple_selectors = ~[]; + let mut simple_selectors = vec!(); match namespace { SpecificNamespace(ns) => simple_selectors.push(NamespaceSelector(ns)), AnyNamespace => (), @@ -526,7 +526,7 @@ fn parse_pseudo_element(name: ~str) -> Option<PseudoElement> { } -//fn parse_lang(arguments: ~[ComponentValue]) -> Option<SimpleSelector> { +//fn parse_lang(arguments: vec!(ComponentValue)) -> Option<SimpleSelector> { // let mut iter = arguments.move_skip_whitespace(); // match iter.next() { // Some(Ident(value)) => { @@ -547,7 +547,7 @@ fn parse_negation(arguments: ~[ComponentValue], namespaces: &NamespaceMap) TypeSelector(s) => s, NotATypeSelector => { match parse_one_simple_selector(iter, namespaces, /* inside_negation = */ true) { - SimpleSelectorResult(s) => ~[s], + SimpleSelectorResult(s) => vec!(s), _ => return None } }, @@ -584,11 +584,11 @@ mod tests { use namespaces::NamespaceMap; use super::*; - fn parse(input: &str) -> Option<~[Selector]> { + fn parse(input: &str) -> Option<Vec<Selector>> { 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( cssparser::tokenize(input).map(|(v, _)| v).collect(), namespaces) @@ -601,113 +601,113 @@ mod tests { #[test] fn test_parsing() { assert!(parse("") == None) - assert!(parse("e") == Some(~[Selector{ + assert!(parse("e") == Some(vec!(Selector{ compound_selectors: Arc::new(CompoundSelector { - simple_selectors: ~[LocalNameSelector("e".to_owned())], + simple_selectors: vec!(LocalNameSelector("e".to_owned())), next: None, }), pseudo_element: None, specificity: specificity(0, 0, 1), - }])) - assert!(parse(".foo") == Some(~[Selector{ + }))) + assert!(parse(".foo") == Some(vec!(Selector{ compound_selectors: Arc::new(CompoundSelector { - simple_selectors: ~[ClassSelector("foo".to_owned())], + simple_selectors: vec!(ClassSelector("foo".to_owned())), next: None, }), pseudo_element: None, specificity: specificity(0, 1, 0), - }])) - assert!(parse("#bar") == Some(~[Selector{ + }))) + assert!(parse("#bar") == Some(vec!(Selector{ compound_selectors: Arc::new(CompoundSelector { - simple_selectors: ~[IDSelector("bar".to_owned())], + simple_selectors: vec!(IDSelector("bar".to_owned())), next: None, }), pseudo_element: None, 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 { - simple_selectors: ~[LocalNameSelector("e".to_owned()), - ClassSelector("foo".to_owned()), - IDSelector("bar".to_owned())], + simple_selectors: vec!(LocalNameSelector("e".to_owned()), + ClassSelector("foo".to_owned()), + IDSelector("bar".to_owned())), next: None, }), pseudo_element: None, 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 { - simple_selectors: ~[IDSelector("bar".to_owned())], + simple_selectors: vec!(IDSelector("bar".to_owned())), next: Some((~CompoundSelector { - simple_selectors: ~[LocalNameSelector("e".to_owned()), - ClassSelector("foo".to_owned())], + simple_selectors: vec!(LocalNameSelector("e".to_owned()), + ClassSelector("foo".to_owned())), next: None, }, Descendant)), }), pseudo_element: None, specificity: specificity(1, 1, 1), - }])) + }))) // Default namespace does not apply to attribute selectors // https://github.com/mozilla/servo/pull/1652 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 { - simple_selectors: ~[AttrExists(AttrSelector { + simple_selectors: vec!(AttrExists(AttrSelector { name: "Foo".to_owned(), lower_name: "foo".to_owned(), namespace: SpecificNamespace(namespace::Null), - })], + })), next: None, }), pseudo_element: None, specificity: specificity(0, 1, 0), - }])) + }))) // Default namespace does not apply to attribute selectors // https://github.com/mozilla/servo/pull/1652 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 { - simple_selectors: ~[AttrExists(AttrSelector { + simple_selectors: vec!(AttrExists(AttrSelector { name: "Foo".to_owned(), lower_name: "foo".to_owned(), namespace: SpecificNamespace(namespace::Null), - })], + })), next: None, }), pseudo_element: None, specificity: specificity(0, 1, 0), - }])) + }))) // 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 { - simple_selectors: ~[ + simple_selectors: vec!( NamespaceSelector(namespace::MathML), LocalNameSelector("e".to_owned()), - ], + ), next: None, }), pseudo_element: None, specificity: specificity(0, 0, 1), - }])) + }))) // https://github.com/mozilla/servo/issues/1723 - assert!(parse("::before") == Some(~[Selector{ + assert!(parse("::before") == Some(vec!(Selector{ compound_selectors: Arc::new(CompoundSelector { - simple_selectors: ~[], + simple_selectors: vec!(), next: None, }), pseudo_element: Some(Before), specificity: specificity(0, 0, 1), - }])) - assert!(parse("div :after") == Some(~[Selector{ + }))) + assert!(parse("div :after") == Some(vec!(Selector{ compound_selectors: Arc::new(CompoundSelector { - simple_selectors: ~[], + simple_selectors: vec!(), next: Some((~CompoundSelector { - simple_selectors: ~[LocalNameSelector("div".to_owned())], + simple_selectors: vec!(LocalNameSelector("div".to_owned())), next: None, }, Descendant)), }), pseudo_element: Some(After), specificity: specificity(0, 0, 2), - }])) + }))) } } diff --git a/src/components/style/stylesheets.rs b/src/components/style/stylesheets.rs index 587b89c2b8b..80ebf02c866 100644 --- a/src/components/style/stylesheets.rs +++ b/src/components/style/stylesheets.rs @@ -21,7 +21,7 @@ use media_queries; pub struct Stylesheet { /// List of rules in the order they were found (important for /// cascading order) - pub rules: ~[CSSRule], + pub rules: Vec<CSSRule>, namespaces: NamespaceMap, encoding: EncodingRef, base_url: Url, @@ -35,7 +35,7 @@ pub enum CSSRule { pub struct StyleRule { - pub selectors: ~[selectors::Selector], + pub selectors: Vec<selectors::Selector>, pub declarations: properties::PropertyDeclarationBlock, } @@ -44,19 +44,20 @@ impl Stylesheet { pub fn from_bytes_iter<I: Iterator<Vec<u8>>>( mut input: I, base_url: Url, protocol_encoding_label: Option<&str>, environment_encoding: Option<EncodingRef>) -> Stylesheet { - let mut bytes = ~[]; + let mut bytes = vec!(); // TODO: incremental decoding and tokinization/parsing for chunk in input { bytes.push_all(chunk.as_slice()) } - Stylesheet::from_bytes(bytes, base_url, protocol_encoding_label, environment_encoding) + Stylesheet::from_bytes(bytes.as_slice(), base_url, protocol_encoding_label, environment_encoding) } pub fn from_bytes( bytes: &[u8], base_url: Url, protocol_encoding_label: Option<&str>, environment_encoding: Option<EncodingRef>) -> Stylesheet { + // TODO: bytes.as_slice could be bytes.container_as_bytes() let (string, used_encoding) = decode_stylesheet_bytes( - bytes, protocol_encoding_label, environment_encoding); + bytes.as_slice(), protocol_encoding_label, environment_encoding); Stylesheet::from_str(string, base_url, used_encoding) } @@ -67,7 +68,7 @@ impl Stylesheet { static STATE_BODY: uint = 4; let mut state: uint = STATE_CHARSET; - let mut rules = ~[]; + let mut rules = vec!(); let mut namespaces = NamespaceMap::new(); for rule in ErrorLoggerIterator(parse_stylesheet_rules(tokenize(css))) { @@ -124,7 +125,7 @@ impl Stylesheet { } -pub fn parse_style_rule(rule: QualifiedRule, parent_rules: &mut ~[CSSRule], +pub fn parse_style_rule(rule: QualifiedRule, parent_rules: &mut Vec<CSSRule>, namespaces: &NamespaceMap, base_url: &Url) { let QualifiedRule{location: location, prelude: prelude, block: block} = rule; // FIXME: avoid doing this for valid selectors @@ -142,7 +143,7 @@ pub fn parse_style_rule(rule: QualifiedRule, parent_rules: &mut ~[CSSRule], // lower_name is passed explicitly to avoid computing it twice. pub fn parse_nested_at_rule(lower_name: &str, rule: AtRule, - parent_rules: &mut ~[CSSRule], namespaces: &NamespaceMap, base_url: &Url) { + parent_rules: &mut Vec<CSSRule>, namespaces: &NamespaceMap, base_url: &Url) { match lower_name { "media" => parse_media_rule(rule, parent_rules, namespaces, base_url), _ => log_css_error(rule.location, format!("Unsupported at-rule: @{:s}", lower_name)) diff --git a/src/components/util/cache.rs b/src/components/util/cache.rs index 450faebebdb..5b8bcf4e03b 100644 --- a/src/components/util/cache.rs +++ b/src/components/util/cache.rs @@ -120,14 +120,14 @@ fn test_hashcache() { } pub struct LRUCache<K, V> { - entries: ~[(K, V)], + entries: Vec<(K, V)>, cache_size: uint, } impl<K: Clone + Eq, V: Clone> LRUCache<K,V> { pub fn new(size: uint) -> LRUCache<K, V> { LRUCache { - entries: ~[], + entries: vec!(), cache_size: size, } } @@ -139,7 +139,7 @@ impl<K: Clone + Eq, V: Clone> LRUCache<K,V> { let entry = self.entries.remove(pos); self.entries.push(entry.unwrap()); } - self.entries[last_index].ref1().clone() + self.entries.get(last_index).ref1().clone() } pub fn iter<'a>(&'a self) -> Items<'a,(K,V)> { diff --git a/src/components/util/time.rs b/src/components/util/time.rs index d05cac3e2f3..151e4385b56 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -63,21 +63,21 @@ impl ProfilerCategory { // enumeration of all ProfilerCategory types fn empty_buckets() -> ProfilerBuckets { let mut buckets = TreeMap::new(); - buckets.insert(CompositingCategory, ~[]); - buckets.insert(LayoutQueryCategory, ~[]); - buckets.insert(LayoutPerformCategory, ~[]); - buckets.insert(LayoutStyleRecalcCategory, ~[]); - buckets.insert(LayoutSelectorMatchCategory, ~[]); - buckets.insert(LayoutTreeBuilderCategory, ~[]); - buckets.insert(LayoutMainCategory, ~[]); - buckets.insert(LayoutParallelWarmupCategory, ~[]); - buckets.insert(LayoutShapingCategory, ~[]); - buckets.insert(LayoutDamagePropagateCategory, ~[]); - buckets.insert(LayoutDispListBuildCategory, ~[]); - buckets.insert(GfxRegenAvailableFontsCategory, ~[]); - buckets.insert(RenderingDrawingCategory, ~[]); - buckets.insert(RenderingPrepBuffCategory, ~[]); - buckets.insert(RenderingCategory, ~[]); + buckets.insert(CompositingCategory, vec!()); + buckets.insert(LayoutQueryCategory, vec!()); + buckets.insert(LayoutPerformCategory, vec!()); + buckets.insert(LayoutStyleRecalcCategory, vec!()); + buckets.insert(LayoutSelectorMatchCategory, vec!()); + buckets.insert(LayoutTreeBuilderCategory, vec!()); + buckets.insert(LayoutMainCategory, vec!()); + buckets.insert(LayoutParallelWarmupCategory, vec!()); + buckets.insert(LayoutShapingCategory, vec!()); + buckets.insert(LayoutDamagePropagateCategory, vec!()); + buckets.insert(LayoutDispListBuildCategory, vec!()); + buckets.insert(GfxRegenAvailableFontsCategory, vec!()); + buckets.insert(RenderingDrawingCategory, vec!()); + buckets.insert(RenderingPrepBuffCategory, vec!()); + buckets.insert(RenderingCategory, vec!()); buckets } @@ -100,7 +100,7 @@ impl ProfilerCategory { } } -type ProfilerBuckets = TreeMap<ProfilerCategory, ~[f64]>; +type ProfilerBuckets = TreeMap<ProfilerCategory, Vec<f64>>; // back end of the profiler that handles data aggregation and performance metrics pub struct Profiler { @@ -200,7 +200,7 @@ impl Profiler { if data_len > 0 { let (mean, median, min, max) = (data.iter().map(|&x|x).sum() / (data_len as f64), - data[data_len / 2], + *data.get(data_len / 2), data.iter().fold(f64::INFINITY, |a, &b| a.min(b)), data.iter().fold(-f64::INFINITY, |a, &b| a.max(b))); println!("{:-35s}: {:15.4f} {:15.4f} {:15.4f} {:15.4f} {:15u}", diff --git a/src/components/util/url.rs b/src/components/util/url.rs index 757a2acf605..9d673bbfb57 100644 --- a/src/components/util/url.rs +++ b/src/components/util/url.rs @@ -4,7 +4,6 @@ use collections::HashMap; use std::os; -use std::vec::Vec; use std_url; use std_url::Url; @@ -39,7 +38,7 @@ pub fn parse_url(str_url: &str, base_url: Option<std_url::Url>) -> std_url::Url debug!("parse_url: base_url: {:?}", base_url); let mut new_url = base_url.clone(); - new_url.query = Vec::new(); + new_url.query = vec!(); new_url.fragment = None; if str_url.starts_with("//") { diff --git a/src/test/harness/contenttest/contenttest.rs b/src/test/harness/contenttest/contenttest.rs index 49087c937b6..ce6cecba5d8 100644 --- a/src/test/harness/contenttest/contenttest.rs +++ b/src/test/harness/contenttest/contenttest.rs @@ -108,7 +108,7 @@ fn run_test(file: ~str) { Ok(p) => p, _ => fail!("Unable to configure process."), }; - let mut output = ~[]; + let mut output = Vec::new(); loop { let byte = prc.stdout.get_mut_ref().read_byte(); match byte { @@ -120,7 +120,7 @@ fn run_test(file: ~str) { } } - let out = str::from_utf8(output); + let out = str::from_utf8(output.as_slice()); let lines: ~[&str] = out.unwrap().split('\n').collect(); for &line in lines.iter() { if line.contains("TEST-UNEXPECTED-FAIL") { |