diff --git a/servo/src/components/gfx/font.rs b/servo/src/components/gfx/font.rs index aa389e00664c..a77ca3a2a299 100644 --- a/servo/src/components/gfx/font.rs +++ b/servo/src/components/gfx/font.rs @@ -33,7 +33,7 @@ use text::{Shaper, TextRun}; // resources needed by the graphics layer to draw glyphs. pub trait FontHandleMethods { - fn new_from_buffer(fctx: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) + fn new_from_buffer(fctx: &FontContextHandle, buf: Vec, style: &SpecifiedFontStyle) -> Result; // an identifier usable by FontContextHandle to recreate this FontHandle. @@ -216,9 +216,9 @@ pub struct Font { impl<'a> Font { pub fn new_from_buffer(ctx: &FontContext, - buffer: ~[u8], - style: &SpecifiedFontStyle, - backend: BackendType) + buffer: Vec, + style: &SpecifiedFontStyle, + backend: BackendType) -> Result>, ()> { let handle = FontHandleMethods::new_from_buffer(&ctx.handle, buffer, style); let handle: FontHandle = if handle.is_ok() { diff --git a/servo/src/components/gfx/platform/android/font.rs b/servo/src/components/gfx/platform/android/font.rs index 3601e0e73f0b..b8a4f110cc4c 100644 --- a/servo/src/components/gfx/platform/android/font.rs +++ b/servo/src/components/gfx/platform/android/font.rs @@ -47,7 +47,7 @@ impl FontTableMethods for FontTable { } enum FontSource { - FontSourceMem(~[u8]), + FontSourceMem(Vec), FontSourceFile(~str) } @@ -73,8 +73,8 @@ impl Drop for FontHandle { impl FontHandleMethods for FontHandle { fn new_from_buffer(fctx: &FontContextHandle, - buf: ~[u8], - style: &SpecifiedFontStyle) + buf: Vec, + style: &SpecifiedFontStyle) -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } diff --git a/servo/src/components/gfx/platform/linux/font.rs b/servo/src/components/gfx/platform/linux/font.rs index 16beabe4a56b..94527b3b35d0 100644 --- a/servo/src/components/gfx/platform/linux/font.rs +++ b/servo/src/components/gfx/platform/linux/font.rs @@ -47,7 +47,7 @@ impl FontTableMethods for FontTable { } pub enum FontSource { - FontSourceMem(~[u8]), + FontSourceMem(Vec), FontSourceFile(~str) } @@ -73,8 +73,8 @@ impl Drop for FontHandle { impl FontHandleMethods for FontHandle { fn new_from_buffer(fctx: &FontContextHandle, - buf: ~[u8], - style: &SpecifiedFontStyle) + buf: Vec, + style: &SpecifiedFontStyle) -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } diff --git a/servo/src/components/gfx/platform/macos/font.rs b/servo/src/components/gfx/platform/macos/font.rs index 2e3b0246511d..5441415b653d 100644 --- a/servo/src/components/gfx/platform/macos/font.rs +++ b/servo/src/components/gfx/platform/macos/font.rs @@ -77,9 +77,9 @@ impl FontHandle { } impl FontHandleMethods for FontHandle { - fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) + fn new_from_buffer(_: &FontContextHandle, buf: Vec, style: &SpecifiedFontStyle) -> Result { - let fontprov = CGDataProvider::from_buffer(buf); + let fontprov = CGDataProvider::from_buffer(buf.as_slice()); let cgfont = CGFont::from_data_provider(fontprov); let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size); diff --git a/servo/src/components/gfx/text/glyph.rs b/servo/src/components/gfx/text/glyph.rs index 1d1b99a8abcb..2e6098e9fa3f 100644 --- a/servo/src/components/gfx/text/glyph.rs +++ b/servo/src/components/gfx/text/glyph.rs @@ -467,7 +467,7 @@ pub enum GlyphInfo<'a> { impl<'a> GlyphInfo<'a> { pub fn index(self) -> GlyphIndex { match self { - SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].index(), + SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i).index(), DetailGlyphInfo(store, entry_i, detail_j) => { store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).index } @@ -478,7 +478,7 @@ impl<'a> GlyphInfo<'a> { // FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _ pub fn advance(self) -> Au { match self { - SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].advance(), + SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i).advance(), DetailGlyphInfo(store, entry_i, detail_j) => { store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance } @@ -499,7 +499,7 @@ impl<'a> GlyphInfo<'a> { pub struct GlyphStore { // TODO(pcwalton): Allocation of this buffer is expensive. Consider a small-vector // optimization. - entry_buffer: ~[GlyphEntry], + entry_buffer: Vec, detail_store: DetailedGlyphStore, @@ -513,7 +513,7 @@ impl<'a> GlyphStore { assert!(length > 0); GlyphStore { - entry_buffer: slice::from_elem(length, GlyphEntry::initial()), + entry_buffer: Vec::from_elem(length, GlyphEntry::initial()), detail_store: DetailedGlyphStore::new(), is_whitespace: is_whitespace, } @@ -550,9 +550,9 @@ impl<'a> GlyphStore { self.detail_store.add_detailed_glyphs_for_entry(i, glyph); GlyphEntry::complex(data.cluster_start, data.ligature_start, 1) } - }.adapt_character_flags_of_entry(self.entry_buffer[i]); + }.adapt_character_flags_of_entry(*self.entry_buffer.get(i)); - self.entry_buffer[i] = entry; + *self.entry_buffer.get_mut(i) = entry; } pub fn add_glyphs_for_char_index(&mut self, i: uint, data_for_glyphs: &[GlyphData]) { @@ -576,11 +576,11 @@ impl<'a> GlyphStore { first_glyph_data.ligature_start, glyph_count) } - }.adapt_character_flags_of_entry(self.entry_buffer[i]); + }.adapt_character_flags_of_entry(*self.entry_buffer.get(i)); debug!("Adding multiple glyphs[idx={:u}, count={:u}]: {:?}", i, glyph_count, entry); - self.entry_buffer[i] = entry; + *self.entry_buffer.get_mut(i) = entry; } // used when a character index has no associated glyph---for example, a ligature continuation. @@ -590,7 +590,7 @@ impl<'a> GlyphStore { let entry = GlyphEntry::complex(cluster_start, ligature_start, 0); debug!("adding spacer for chracter without associated glyph[idx={:u}]", i); - self.entry_buffer[i] = entry; + *self.entry_buffer.get_mut(i) = entry; } pub fn iter_glyphs_for_char_index(&'a self, i: uint) -> GlyphIterator<'a> { @@ -617,57 +617,57 @@ impl<'a> GlyphStore { // getter methods pub fn char_is_space(&self, i: uint) -> bool { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].char_is_space() + self.entry_buffer.get(i).char_is_space() } pub fn char_is_tab(&self, i: uint) -> bool { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].char_is_tab() + self.entry_buffer.get(i).char_is_tab() } pub fn char_is_newline(&self, i: uint) -> bool { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].char_is_newline() + self.entry_buffer.get(i).char_is_newline() } pub fn is_ligature_start(&self, i: uint) -> bool { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].is_ligature_start() + self.entry_buffer.get(i).is_ligature_start() } pub fn is_cluster_start(&self, i: uint) -> bool { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].is_cluster_start() + self.entry_buffer.get(i).is_cluster_start() } pub fn can_break_before(&self, i: uint) -> BreakType { assert!(i < self.entry_buffer.len()); - self.entry_buffer[i].can_break_before() + self.entry_buffer.get(i).can_break_before() } // setter methods pub fn set_char_is_space(&mut self, i: uint) { assert!(i < self.entry_buffer.len()); - let entry = self.entry_buffer[i]; - self.entry_buffer[i] = entry.set_char_is_space(); + let entry = *self.entry_buffer.get(i); + *self.entry_buffer.get_mut(i) = entry.set_char_is_space(); } pub fn set_char_is_tab(&mut self, i: uint) { assert!(i < self.entry_buffer.len()); - let entry = self.entry_buffer[i]; - self.entry_buffer[i] = entry.set_char_is_tab(); + let entry = *self.entry_buffer.get(i); + *self.entry_buffer.get_mut(i) = entry.set_char_is_tab(); } pub fn set_char_is_newline(&mut self, i: uint) { assert!(i < self.entry_buffer.len()); - let entry = self.entry_buffer[i]; - self.entry_buffer[i] = entry.set_char_is_newline(); + let entry = *self.entry_buffer.get(i); + *self.entry_buffer.get_mut(i) = entry.set_char_is_newline(); } pub fn set_can_break_before(&mut self, i: uint, t: BreakType) { assert!(i < self.entry_buffer.len()); - let entry = self.entry_buffer[i]; - self.entry_buffer[i] = entry.set_can_break_before(t); + let entry = *self.entry_buffer.get(i); + *self.entry_buffer.get_mut(i) = entry.set_can_break_before(t); } } @@ -722,7 +722,7 @@ impl<'a> Iterator<(uint, GlyphInfo<'a>)> for GlyphIterator<'a> { Some(i) => { self.char_index = i; assert!(i < self.store.entry_buffer.len()); - let entry = &self.store.entry_buffer[i]; + let entry = self.store.entry_buffer.get(i); if entry.is_simple() { Some((self.char_index, SimpleGlyphInfo(self.store, i))) } else { diff --git a/servo/src/components/main/constellation.rs b/servo/src/components/main/constellation.rs index 4de6ca198202..94c5d0e10393 100644 --- a/servo/src/components/main/constellation.rs +++ b/servo/src/components/main/constellation.rs @@ -76,7 +76,7 @@ impl Clone for ChildFrameTree { pub struct SendableFrameTree { pub pipeline: CompositionPipeline, - pub children: ~[SendableChildFrameTree], + pub children: Vec, } pub struct SendableChildFrameTree { @@ -133,7 +133,7 @@ impl FrameTreeTraversal for Rc { fn iter(&self) -> FrameTreeIterator { FrameTreeIterator { - stack: ~[self.clone()], + stack: vec!(self.clone()), } } } @@ -151,7 +151,7 @@ impl ChildFrameTree { /// Note that this iterator should _not_ be used to mutate nodes _during_ /// iteration. Mutating nodes once the iterator is out of scope is OK. struct FrameTreeIterator { - stack: ~[Rc], + stack: Vec>, } impl Iterator> for FrameTreeIterator { @@ -220,7 +220,7 @@ impl NavigationContext { } /// Returns the frame trees whose keys are pipeline_id. - fn find_all(&mut self, pipeline_id: PipelineId) -> ~[Rc] { + fn find_all(&mut self, pipeline_id: PipelineId) -> Vec> { let from_current = self.current.iter().filter_map(|frame_tree| { frame_tree.find(pipeline_id) }); @@ -300,7 +300,7 @@ impl Constellation { } /// Returns both the navigation context and pending frame trees whose keys are pipeline_id. - fn find_all(&mut self, pipeline_id: PipelineId) -> ~[Rc] { + fn find_all(&mut self, pipeline_id: PipelineId) -> Vec> { let matching_navi_frames = self.navigation_context.find_all(pipeline_id); let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| { frame_change.after.find(pipeline_id) @@ -548,7 +548,7 @@ impl Constellation { // or a new url entered. // Start by finding the frame trees matching the pipeline id, // and add the new pipeline to their sub frames. - let frame_trees: ~[Rc] = { + let frame_trees: Vec> = { let matching_navi_frames = self.navigation_context.find_all(source_pipeline_id); let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| { frame_change.after.find(source_pipeline_id) diff --git a/servo/src/components/main/layout/construct.rs b/servo/src/components/main/layout/construct.rs index 42a3d87ee0e7..b5aeaa65d2b9 100644 --- a/servo/src/components/main/layout/construct.rs +++ b/servo/src/components/main/layout/construct.rs @@ -170,69 +170,6 @@ impl InlineBlockSplit { } } -/// Methods on optional vectors. -/// -/// TODO(pcwalton): I think this will no longer be necessary once Rust #8981 lands. -pub trait OptVector { - /// 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) -> ~[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: ~[T]); - - /// Pushes an optional vector onto this vector, consuming the original. - fn push_opt_vec_move(&mut self, values: Self); - - /// Returns the length of this optional vector. - fn len(&self) -> uint; -} - -impl OptVector for Option<~[T]> { - #[inline] - fn to_vec(self) -> ~[T] { - match self { - None => ~[], - Some(vector) => vector, - } - } - - #[inline] - fn push(&mut self, value: T) { - match *self { - None => *self = Some(~[value]), - Some(ref mut vector) => vector.push(value), - } - } - - #[inline] - fn push_all_move(&mut self, values: ~[T]) { - match *self { - None => *self = Some(values), - Some(ref mut vector) => vector.push_all_move(values), - } - } - - #[inline] - fn push_opt_vec_move(&mut self, values: Option<~[T]>) { - match values { - None => {} - Some(values) => self.push_all_move(values), - } - } - - #[inline] - fn len(&self) -> uint { - match *self { - None => 0, - Some(ref vector) => vector.len(), - } - } -} - /// Holds inline boxes that we're gathering for children of an inline node. struct InlineBoxAccumulator { /// The list of boxes. diff --git a/servo/src/components/style/selector_matching.rs b/servo/src/components/style/selector_matching.rs index c45d56acf404..eaeedc5995ac 100644 --- a/servo/src/components/style/selector_matching.rs +++ b/servo/src/components/style/selector_matching.rs @@ -80,11 +80,11 @@ impl<'a> Hash for LowercaseAsciiString<'a> { struct SelectorMap { // TODO: Tune the initial capacity of the HashMap // FIXME: Use interned strings - id_hash: HashMap, - class_hash: HashMap, - element_hash: HashMap, + id_hash: HashMap>, + class_hash: HashMap>, + element_hash: HashMap>, // For Rules that don't have ID, class, or element selectors. - universal_rules: ~[Rule], + universal_rules: Vec, /// Whether this hash is empty. empty: bool, } @@ -95,7 +95,7 @@ impl SelectorMap { id_hash: HashMap::new(), class_hash: HashMap::new(), element_hash: HashMap::new(), - universal_rules: ~[], + universal_rules: vec!(), empty: true, } } @@ -151,7 +151,7 @@ impl SelectorMap { shareable); SelectorMap::get_matching_rules(node, - self.universal_rules, + self.universal_rules.as_slice(), matching_rules_list, shareable); @@ -163,13 +163,13 @@ impl SelectorMap { N:TNode, V:SmallVec>( node: &N, - hash: &HashMap, + hash: &HashMap>, key: &str, matching_rules: &mut V, shareable: &mut bool) { match hash.find_equiv(&key) { Some(rules) => { - SelectorMap::get_matching_rules(node, *rules, matching_rules, shareable) + SelectorMap::get_matching_rules(node, rules.as_slice(), matching_rules, shareable) } None => {} } @@ -179,13 +179,13 @@ impl SelectorMap { N:TNode, V:SmallVec>( node: &N, - hash: &HashMap, + hash: &HashMap>, key: &str, matching_rules: &mut V, shareable: &mut bool) { match hash.find_equiv(&LowercaseAsciiString(key)) { Some(rules) => { - SelectorMap::get_matching_rules(node, *rules, matching_rules, shareable) + SelectorMap::get_matching_rules(node, rules.as_slice(), matching_rules, shareable) } None => {} } @@ -221,7 +221,7 @@ impl SelectorMap { } None => {} } - self.id_hash.insert(id_name, ~[rule]); + self.id_hash.insert(id_name, vec!(rule)); return; } None => {} @@ -235,7 +235,7 @@ impl SelectorMap { } None => {} } - self.class_hash.insert(class_name, ~[rule]); + self.class_hash.insert(class_name, vec!(rule)); return; } None => {} @@ -250,7 +250,7 @@ impl SelectorMap { } None => {} } - self.element_hash.insert(element_name, ~[rule]); + self.element_hash.insert(element_name, vec!(rule)); return; } None => {} @@ -947,7 +947,7 @@ mod tests { /// Helper method to get some Rules from selector strings. /// Each sublist of the result contains the Rules for one StyleRule. - fn get_mock_rules(css_selectors: &[&str]) -> ~[~[Rule]] { + fn get_mock_rules(css_selectors: &[&str]) -> Vec> { use namespaces::NamespaceMap; use selectors::parse_selector_list; use cssparser::tokenize; @@ -971,42 +971,42 @@ mod tests { #[test] fn test_rule_ordering_same_specificity(){ let rules_list = get_mock_rules(["a.intro", "img.sidebar"]); - let rule1 = rules_list[0][0].clone(); - let rule2 = rules_list[1][0].clone(); + let rule1 = rules_list.get(0).get(0).clone(); + let rule2 = rules_list.get(1).get(0).clone(); assert!(rule1.property < rule2.property, "The rule that comes later should win."); } #[test] fn test_get_id_name(){ let rules_list = get_mock_rules([".intro", "#top"]); - assert_eq!(SelectorMap::get_id_name(&rules_list[0][0]), None); - assert_eq!(SelectorMap::get_id_name(&rules_list[1][0]), Some("top".to_owned())); + assert_eq!(SelectorMap::get_id_name(rules_list.get(0).get(0)), None); + assert_eq!(SelectorMap::get_id_name(rules_list.get(1).get(0)), Some("top".to_owned())); } #[test] fn test_get_class_name(){ let rules_list = get_mock_rules([".intro.foo", "#top"]); - assert_eq!(SelectorMap::get_class_name(&rules_list[0][0]), Some("intro".to_owned())); - assert_eq!(SelectorMap::get_class_name(&rules_list[1][0]), None); + assert_eq!(SelectorMap::get_class_name(rules_list.get(0).get(0)), Some("intro".to_owned())); + assert_eq!(SelectorMap::get_class_name(rules_list.get(1).get(0)), None); } #[test] fn test_get_element_name(){ let rules_list = get_mock_rules(["img.foo", "#top", "IMG", "ImG"]); - assert_eq!(SelectorMap::get_element_name(&rules_list[0][0]), Some("img".to_owned())); - assert_eq!(SelectorMap::get_element_name(&rules_list[1][0]), None); - assert_eq!(SelectorMap::get_element_name(&rules_list[2][0]), Some("img".to_owned())); - assert_eq!(SelectorMap::get_element_name(&rules_list[3][0]), Some("img".to_owned())); + assert_eq!(SelectorMap::get_element_name(rules_list.get(0).get(0)), Some("img".to_owned())); + assert_eq!(SelectorMap::get_element_name(rules_list.get(1).get(0)), None); + assert_eq!(SelectorMap::get_element_name(rules_list.get(2).get(0)), Some("img".to_owned())); + assert_eq!(SelectorMap::get_element_name(rules_list.get(3).get(0)), Some("img".to_owned())); } #[test] fn test_insert(){ let rules_list = get_mock_rules([".intro.foo", "#top"]); let mut selector_map = SelectorMap::new(); - selector_map.insert(rules_list[1][0].clone()); - assert_eq!(1, selector_map.id_hash.find_equiv(& &"top").unwrap()[0].property.source_order); - selector_map.insert(rules_list[0][0].clone()); - assert_eq!(0, selector_map.class_hash.find_equiv(& &"intro").unwrap()[0].property.source_order); + selector_map.insert(rules_list.get(1).get(0).clone()); + assert_eq!(1, selector_map.id_hash.find_equiv(& &"top").unwrap().get(0).property.source_order); + selector_map.insert(rules_list.get(0).get(0).clone()); + assert_eq!(0, selector_map.class_hash.find_equiv(& &"intro").unwrap().get(0).property.source_order); assert!(selector_map.class_hash.find_equiv(& &"foo").is_none()); } }