diff --git a/src/components/gfx/font_list.rs b/src/components/gfx/font_list.rs index ceda9619eb52..686d72d1ad66 100644 --- a/src/components/gfx/font_list.rs +++ b/src/components/gfx/font_list.rs @@ -18,7 +18,7 @@ pub type FontFamilyMap = HashMap<~str, FontFamily>; trait FontListHandleMethods { fn get_available_families(&self, fctx: &FontContextHandle) -> FontFamilyMap; fn load_variations_for_family(&self, family: &mut FontFamily); - fn get_last_resort_font_families() -> ~[~str]; + fn get_last_resort_font_families() -> Vec<~str>; } /// The platform-independent font list abstraction. @@ -75,9 +75,8 @@ impl FontList { } } - pub fn get_last_resort_font_families() -> ~[~str] { - let last_resort = FontListHandle::get_last_resort_font_families(); - last_resort + pub fn get_last_resort_font_families() -> Vec<~str> { + FontListHandle::get_last_resort_font_families() } } diff --git a/src/components/gfx/platform/android/font_list.rs b/src/components/gfx/platform/android/font_list.rs index 90bfcf0e4815..8d5649096b73 100644 --- a/src/components/gfx/platform/android/font_list.rs +++ b/src/components/gfx/platform/android/font_list.rs @@ -129,8 +129,8 @@ impl FontListHandle { } } - pub fn get_last_resort_font_families() -> ~[~str] { - ~["Roboto".to_owned()] + pub fn get_last_resort_font_families() -> Vec<~str> { + vec!("Roboto".to_owned()) } } diff --git a/src/components/gfx/platform/linux/font_list.rs b/src/components/gfx/platform/linux/font_list.rs index cb3bcc5ed165..d64c90e9db9f 100644 --- a/src/components/gfx/platform/linux/font_list.rs +++ b/src/components/gfx/platform/linux/font_list.rs @@ -131,8 +131,8 @@ impl FontListHandle { } } - pub fn get_last_resort_font_families() -> ~[~str] { - ~["Arial".to_owned()] + pub fn get_last_resort_font_families() -> Vec<~str> { + vec!("Arial".to_owned()) } } diff --git a/src/components/gfx/platform/macos/font_list.rs b/src/components/gfx/platform/macos/font_list.rs index a260cf23c4f5..9171bd3d0f68 100644 --- a/src/components/gfx/platform/macos/font_list.rs +++ b/src/components/gfx/platform/macos/font_list.rs @@ -58,7 +58,7 @@ impl FontListHandle { } } - pub fn get_last_resort_font_families() -> ~[~str] { - ~["Arial Unicode MS".to_owned(),"Arial".to_owned()] + pub fn get_last_resort_font_families() -> Vec<~str> { + vec!("Arial Unicode MS".to_owned(), "Arial".to_owned()) } } diff --git a/src/components/gfx/text/util.rs b/src/components/gfx/text/util.rs index 1f4fa172018b..eda9e889ff9c 100644 --- a/src/components/gfx/text/util.rs +++ b/src/components/gfx/text/util.rs @@ -138,49 +138,53 @@ fn test_true_type_tag() { #[test] fn test_transform_compress_none() { - - let test_strs : ~[~str] = ~[" foo bar".to_owned(), - "foo bar ".to_owned(), - "foo\n bar".to_owned(), - "foo \nbar".to_owned(), - " foo bar \nbaz".to_owned(), - "foo bar baz".to_owned(), - "foobarbaz\n\n".to_owned()]; + let test_strs = vec!( + " foo bar", + "foo bar ", + "foo\n bar", + "foo \nbar", + " foo bar \nbaz", + "foo bar baz", + "foobarbaz\n\n" + ); let mode = CompressNone; - for i in range(0, test_strs.len()) { + for test in test_strs.iter() { 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]) + let (trimmed_str, _out) = transform_text(*test, mode, true, &mut new_line_pos); + assert_eq!(trimmed_str.as_slice(), *test) } } #[test] fn test_transform_discard_newline() { - - let test_strs : ~[~str] = ~[" foo bar".to_owned(), - "foo bar ".to_owned(), - "foo\n bar".to_owned(), - "foo \nbar".to_owned(), - " foo bar \nbaz".to_owned(), - "foo bar baz".to_owned(), - "foobarbaz\n\n".to_owned()]; - - let oracle_strs : ~[~str] = ~[" foo bar".to_owned(), - "foo bar ".to_owned(), - "foo bar".to_owned(), - "foo bar".to_owned(), - " foo bar baz".to_owned(), - "foo bar baz".to_owned(), - "foobarbaz".to_owned()]; + let test_strs = vec!( + " foo bar", + "foo bar ", + "foo\n bar", + "foo \nbar", + " foo bar \nbaz", + "foo bar baz", + "foobarbaz\n\n" + ); + + let oracle_strs = vec!( + " foo bar", + "foo bar ", + "foo bar", + "foo bar", + " foo bar baz", + "foo bar baz", + "foobarbaz" + ); assert_eq!(test_strs.len(), oracle_strs.len()); let mode = DiscardNewline; - for i in range(0, test_strs.len()) { + for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) { 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]) + let (trimmed_str, _out) = transform_text(*test, mode, true, &mut new_line_pos); + assert_eq!(trimmed_str.as_slice(), *oracle) } } @@ -244,30 +248,34 @@ fn test_transform_compress_whitespace_newline() { #[test] fn test_transform_compress_whitespace_newline_no_incoming() { - let test_strs : ~[~str] = ~[" foo bar".to_owned(), - "\nfoo bar".to_owned(), - "foo bar ".to_owned(), - "foo\n bar".to_owned(), - "foo \nbar".to_owned(), - " foo bar \nbaz".to_owned(), - "foo bar baz".to_owned(), - "foobarbaz\n\n".to_owned()]; - - let oracle_strs : ~[~str] = ~[" foo bar".to_owned(), - " foo bar".to_owned(), - "foo bar ".to_owned(), - "foo bar".to_owned(), - "foo bar".to_owned(), - " foo bar baz".to_owned(), - "foo bar baz".to_owned(), - "foobarbaz ".to_owned()]; + let test_strs = vec!( + " foo bar", + "\nfoo bar", + "foo bar ", + "foo\n bar", + "foo \nbar", + " foo bar \nbaz", + "foo bar baz", + "foobarbaz\n\n" + ); + + let oracle_strs = vec!( + " foo bar", + " foo bar", + "foo bar ", + "foo bar", + "foo bar", + " foo bar baz", + "foo bar baz", + "foobarbaz " + ); assert_eq!(test_strs.len(), oracle_strs.len()); let mode = CompressWhitespaceNewline; - for i in range(0, test_strs.len()) { + for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) { 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]) + let (trimmed_str, _out) = transform_text(*test, mode, false, &mut new_line_pos); + assert_eq!(trimmed_str.as_slice(), *oracle) } } diff --git a/src/components/main/compositing/compositor_task.rs b/src/components/main/compositing/compositor_task.rs index 4e119f3fb42f..a63068b5d0cf 100644 --- a/src/components/main/compositing/compositor_task.rs +++ b/src/components/main/compositing/compositor_task.rs @@ -81,7 +81,7 @@ impl RenderListener for CompositorChan { fn initialize_layers_for_pipeline(&self, pipeline_id: PipelineId, - metadata: ~[LayerMetadata], + metadata: Vec, epoch: Epoch) { // FIXME(#2004, pcwalton): This assumes that the first layer determines the page size, and // that all other layers are immediate children of it. This is sufficient to handle diff --git a/src/components/msg/compositor_msg.rs b/src/components/msg/compositor_msg.rs index 1b71e2035966..6ce3a65a451e 100644 --- a/src/components/msg/compositor_msg.rs +++ b/src/components/msg/compositor_msg.rs @@ -126,7 +126,7 @@ pub trait RenderListener { /// creating and/or destroying render layers as necessary. fn initialize_layers_for_pipeline(&self, pipeline_id: PipelineId, - metadata: ~[LayerMetadata], + metadata: Vec, epoch: Epoch); fn set_layer_clip_rect(&self, diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index a88c5e6da3db..93369fc5cbdb 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -126,15 +126,15 @@ type LoaderTaskFactory = extern "Rust" fn() -> LoaderTask; /// Create a ResourceTask with the default loaders pub fn ResourceTask() -> ResourceTask { - let loaders = ~[ + let loaders = vec!( ("file".to_owned(), file_loader::factory), ("http".to_owned(), http_loader::factory), ("data".to_owned(), data_loader::factory), - ]; + ); create_resource_task_with_loaders(loaders) } -fn create_resource_task_with_loaders(loaders: ~[(~str, LoaderTaskFactory)]) -> ResourceTask { +fn create_resource_task_with_loaders(loaders: Vec<(~str, LoaderTaskFactory)>) -> ResourceTask { let (setup_chan, setup_port) = channel(); let builder = task::task().named("ResourceManager"); builder.spawn(proc() { @@ -148,12 +148,12 @@ fn create_resource_task_with_loaders(loaders: ~[(~str, LoaderTaskFactory)]) -> R struct ResourceManager { from_client: Receiver, /// Per-scheme resource loaders - loaders: ~[(~str, LoaderTaskFactory)], + loaders: Vec<(~str, LoaderTaskFactory)>, } fn ResourceManager(from_client: Receiver, - loaders: ~[(~str, LoaderTaskFactory)]) -> ResourceManager { + loaders: Vec<(~str, LoaderTaskFactory)>) -> ResourceManager { ResourceManager { from_client : from_client, loaders : loaders, @@ -236,7 +236,7 @@ fn snicklefritz_loader_factory() -> LoaderTask { #[test] fn should_delegate_to_scheme_loader() { - let loader_factories = ~[("snicklefritz".to_owned(), snicklefritz_loader_factory)]; + let loader_factories = vec!(("snicklefritz".to_owned(), snicklefritz_loader_factory)); let resource_task = create_resource_task_with_loaders(loader_factories); let (start_chan, start) = channel(); resource_task.send(Load(FromStr::from_str("snicklefritz://heya").unwrap(), start_chan)); diff --git a/src/components/util/concurrentmap.rs b/src/components/util/concurrentmap.rs index 0fa4f659bb86..1a2fbd404cf6 100644 --- a/src/components/util/concurrentmap.rs +++ b/src/components/util/concurrentmap.rs @@ -12,7 +12,6 @@ use std::ptr; use std::sync::atomics::{AtomicUint, Relaxed, SeqCst}; use std::unstable::mutex::StaticNativeMutex; use std::mem; -use std::slice; /// When the size exceeds (number of buckets * LOAD_NUMERATOR/LOAD_DENOMINATOR), the hash table /// grows. @@ -38,9 +37,9 @@ pub struct ConcurrentHashMap { /// The number of elements in this hash table. size: AtomicUint, /// The striped locks. - locks: ~[StaticNativeMutex], + locks: Vec, /// The buckets. - buckets: ~[Option>], + buckets: Vec>>, } impl ConcurrentHashMap { @@ -57,12 +56,12 @@ impl ConcurrentHashMap { k0: rand.gen(), k1: rand.gen(), size: AtomicUint::new(0), - locks: slice::from_fn(lock_count, |_| { + locks: Vec::from_fn(lock_count, |_| { unsafe { StaticNativeMutex::new() } }), - buckets: slice::from_fn(lock_count * buckets_per_lock, |_| None), + buckets: Vec::from_fn(lock_count * buckets_per_lock, |_| None), } } @@ -75,7 +74,7 @@ impl ConcurrentHashMap { loop { let (bucket_index, lock_index) = self.bucket_and_lock_indices(&key); if this.overloaded() { - this.locks[lock_index].unlock_noguard(); + this.locks.get(lock_index).unlock_noguard(); this.try_resize(self.buckets_per_lock() * 2); // Have to retry because the bucket and lock indices will have shifted. @@ -83,7 +82,7 @@ impl ConcurrentHashMap { } this.insert_unlocked(key, value, Some(bucket_index)); - this.locks[lock_index].unlock_noguard(); + this.locks.get(lock_index).unlock_noguard(); break } } @@ -98,16 +97,9 @@ impl ConcurrentHashMap { None => self.bucket_index_unlocked(&key), }; - match this.buckets[bucket_index] { - None => { - this.buckets[bucket_index] = Some(Bucket { - next: None, - key: key, - value: value, - }); - drop(this.size.fetch_add(1, SeqCst)); - } - Some(ref mut bucket) => { + match this.buckets.get_mut(bucket_index) { + &None => {} + &Some(ref mut bucket) => { // Search to try to find a value. let mut bucket: *mut Bucket = bucket; loop { @@ -132,8 +124,15 @@ impl ConcurrentHashMap { drop(this.size.fetch_add(1, SeqCst)); break } + return; } } + *this.buckets.get_mut(bucket_index) = Some(Bucket { + next: None, + key: key, + value: value, + }); + drop(this.size.fetch_add(1, SeqCst)); } /// Removes the given key from the hash table. @@ -146,9 +145,9 @@ impl ConcurrentHashMap { // Rebuild the bucket. let mut nuke_bucket = false; - match this.buckets[bucket_index] { - None => {} - Some(ref mut bucket) if bucket.key == *key => { + match this.buckets.get_mut(bucket_index) { + &None => {} + &Some(ref mut bucket) if bucket.key == *key => { // Common case (assuming a sparse table): If the key is the first one in the // chain, just copy the next fields over. let next_opt = mem::replace(&mut bucket.next, None); @@ -158,7 +157,7 @@ impl ConcurrentHashMap { } drop(this.size.fetch_sub(1, SeqCst)) } - Some(ref mut bucket) => { + &Some(ref mut bucket) => { // Rarer case: If the key is elsewhere in the chain (or nowhere), then search for // it and just stitch up pointers. let mut prev: *mut Bucket = bucket; @@ -188,11 +187,11 @@ impl ConcurrentHashMap { } } if nuke_bucket { - this.buckets[bucket_index] = None + *this.buckets.get_mut(bucket_index) = None } unsafe { - this.locks[lock_index].unlock_noguard() + this.locks.get(lock_index).unlock_noguard() } } @@ -214,9 +213,9 @@ impl ConcurrentHashMap { let (bucket_index, lock_index) = this.bucket_and_lock_indices(key); let result; - match this.buckets[bucket_index] { - None => result = false, - Some(ref bucket) => { + match this.buckets.get(bucket_index) { + &None => result = false, + &Some(ref bucket) => { // Search to try to find a value. let mut bucket = bucket; loop { @@ -236,7 +235,7 @@ impl ConcurrentHashMap { } unsafe { - this.locks[lock_index].unlock_noguard() + this.locks.get(lock_index).unlock_noguard() } result @@ -256,7 +255,7 @@ impl ConcurrentHashMap { stripe_index += 1; if stripe_index == buckets_per_lock { unsafe { - this.locks[lock_index].unlock_noguard(); + this.locks.get(lock_index).unlock_noguard(); } stripe_index = 0; @@ -264,7 +263,7 @@ impl ConcurrentHashMap { } if stripe_index == 0 { unsafe { - this.locks[lock_index].lock_noguard() + this.locks.get(lock_index).lock_noguard() } } @@ -295,7 +294,7 @@ impl ConcurrentHashMap { let new_bucket_count = lock_count * new_buckets_per_lock; if new_bucket_count > this.buckets.len() { // Create a new set of buckets. - let mut buckets = slice::from_fn(new_bucket_count, |_| None); + let mut buckets = Vec::from_fn(new_bucket_count, |_| None); mem::swap(&mut this.buckets, &mut buckets); this.size.store(0, Relaxed); @@ -360,7 +359,7 @@ impl ConcurrentHashMap { bucket_index = hash as uint % bucket_count; lock_index = bucket_index / buckets_per_lock; unsafe { - this.locks[lock_index].lock_noguard(); + this.locks.get(lock_index).lock_noguard(); } let new_bucket_count = this.buckets.len(); if bucket_count == new_bucket_count { @@ -369,7 +368,7 @@ impl ConcurrentHashMap { // If we got here, the hash table resized from under us: try again. unsafe { - this.locks[lock_index].unlock_noguard() + this.locks.get(lock_index).unlock_noguard() } } @@ -447,12 +446,12 @@ impl<'a,K,V> Iterator<(&'a K, &'a V)> for ConcurrentHashMapIterator<'a,K,V> { // necessary and acquire the new one, if necessary. if bucket_index != -1 { unsafe { - map.locks[lock_index as uint].unlock_noguard() + map.locks.get(lock_index as uint).unlock_noguard() } } if bucket_index != (bucket_count as int) - 1 { unsafe { - map.locks[(lock_index + 1) as uint].lock_noguard() + map.locks.get((lock_index + 1) as uint).lock_noguard() } } } @@ -464,9 +463,9 @@ impl<'a,K,V> Iterator<(&'a K, &'a V)> for ConcurrentHashMapIterator<'a,K,V> { self.bucket_index += 1; - self.current_bucket = match map.buckets[self.bucket_index as uint] { - None => ptr::null(), - Some(ref bucket) => { + self.current_bucket = match map.buckets.get(self.bucket_index as uint) { + &None => ptr::null(), + &Some(ref bucket) => { let bucket: *Bucket = bucket; bucket } diff --git a/src/components/util/workqueue.rs b/src/components/util/workqueue.rs index 409092bc1714..e7314f10812f 100644 --- a/src/components/util/workqueue.rs +++ b/src/components/util/workqueue.rs @@ -68,7 +68,7 @@ struct WorkerThread { /// The communication channel on which messages are sent to the supervisor. chan: Sender>, /// The thief end of the work-stealing deque for all other workers. - other_deques: ~[Stealer>], + other_deques: Vec>>, /// The random number generator for this worker. rng: XorShiftRng, } @@ -104,7 +104,7 @@ impl WorkerThread { let mut should_continue = true; loop { let victim = (self.rng.next_u32() as uint) % self.other_deques.len(); - match self.other_deques[victim].steal() { + match self.other_deques.get_mut(victim).steal() { Empty | Abort => { // Continue. } @@ -189,7 +189,7 @@ impl<'a,QUD,WUD:Send> WorkerProxy<'a,QUD,WUD> { /// A work queue on which units of work can be submitted. pub struct WorkQueue { /// Information about each of the workers. - workers: ~[WorkerInfo], + workers: Vec>, /// A port on which deques can be received from the workers. port: Receiver>, /// The amount of work that has been enqueued. @@ -204,7 +204,7 @@ impl WorkQueue { pub fn new(task_name: &'static str, thread_count: uint, user_data: QUD) -> WorkQueue { // Set up data structures. let (supervisor_chan, supervisor_port) = channel(); - let (mut infos, mut threads) = (~[], ~[]); + let (mut infos, mut threads) = (vec!(), vec!()); for i in range(0, thread_count) { let (worker_chan, worker_port) = channel(); let mut pool = BufferPool::new(); @@ -219,7 +219,7 @@ impl WorkQueue { index: i, port: worker_port, chan: supervisor_chan.clone(), - other_deques: ~[], + other_deques: vec!(), rng: rand::weak_rng(), }); } @@ -228,10 +228,10 @@ impl WorkQueue { for i in range(0, thread_count) { for j in range(0, thread_count) { if i != j { - threads[i].other_deques.push(infos[j].thief.clone()) + threads.get_mut(i).other_deques.push(infos.get(j).thief.clone()) } } - assert!(threads[i].other_deques.len() == thread_count - 1) + assert!(threads.get(i).other_deques.len() == thread_count - 1) } // Spawn threads. @@ -255,7 +255,7 @@ impl WorkQueue { /// Enqueues a block into the work queue. #[inline] pub fn push(&mut self, work_unit: WorkUnit) { - match self.workers[0].deque { + match self.workers.get_mut(0).deque { None => { fail!("tried to push a block but we don't have the deque?!") } @@ -284,7 +284,7 @@ impl WorkQueue { // Get our deques back. for _ in range(0, self.workers.len()) { match self.port.recv() { - ReturnDequeMsg(index, deque) => self.workers[index].deque = Some(deque), + ReturnDequeMsg(index, deque) => self.workers.get_mut(index).deque = Some(deque), FinishedMsg => fail!("unexpected finished message!"), } }