diff options
author | Jack Moffitt <jack@metajack.im> | 2014-11-05 12:33:11 -0700 |
---|---|---|
committer | Glenn Watson <gw@intuitionlibrary.com> | 2014-11-13 11:17:43 +1000 |
commit | d1b433a3b3bab353f320b2f39fa953ce326d2d55 (patch) | |
tree | d7a197abb65827b36c47e6b5c3adcce9071643d3 /components/util | |
parent | 26045d7fcbab8851fbefe2851cd904203f8fd8dd (diff) | |
download | servo-d1b433a3b3bab353f320b2f39fa953ce326d2d55.tar.gz servo-d1b433a3b3bab353f320b2f39fa953ce326d2d55.zip |
Rust upgrade to rustc hash b03a2755193cd756583bcf5831cf4545d75ecb8a
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/bloom.rs | 9 | ||||
-rw-r--r-- | components/util/cache.rs | 18 | ||||
-rw-r--r-- | components/util/dlist.rs | 5 | ||||
-rw-r--r-- | components/util/fnv.rs | 2 | ||||
-rw-r--r-- | components/util/geometry.rs | 10 | ||||
-rw-r--r-- | components/util/lib.rs | 4 | ||||
-rw-r--r-- | components/util/logical_geometry.rs | 20 | ||||
-rw-r--r-- | components/util/memory.rs | 5 | ||||
-rw-r--r-- | components/util/rtinstrument.rs | 4 | ||||
-rw-r--r-- | components/util/smallvec.rs | 6 | ||||
-rw-r--r-- | components/util/str.rs | 4 | ||||
-rw-r--r-- | components/util/task_state.rs | 22 | ||||
-rw-r--r-- | components/util/tid.rs | 2 | ||||
-rw-r--r-- | components/util/time.rs | 4 | ||||
-rw-r--r-- | components/util/vec.rs | 7 | ||||
-rw-r--r-- | components/util/workqueue.rs | 21 |
16 files changed, 78 insertions, 65 deletions
diff --git a/components/util/bloom.rs b/components/util/bloom.rs index 6795cb889e8..fe56ac2c762 100644 --- a/components/util/bloom.rs +++ b/components/util/bloom.rs @@ -6,10 +6,10 @@ use string_cache::{Atom, Namespace}; -static KEY_SIZE: uint = 12; -static ARRAY_SIZE: uint = 1 << KEY_SIZE; -static KEY_MASK: u32 = (1 << KEY_SIZE) - 1; -static KEY_SHIFT: uint = 16; +const KEY_SIZE: uint = 12; +const ARRAY_SIZE: uint = 1 << KEY_SIZE; +const KEY_MASK: u32 = (1 << KEY_SIZE) - 1; +const KEY_SHIFT: uint = 16; /// A counting Bloom filter with 8-bit counters. For now we assume /// that having two hash functions is enough, but we may revisit that @@ -334,4 +334,3 @@ mod bench { }) } } - diff --git a/components/util/cache.rs b/components/util/cache.rs index 19f861a1d3c..2797bc4e6d6 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -2,7 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::collections::hashmap::HashMap; +use std::collections::HashMap; +use std::collections::hash_map::{Occupied, Vacant}; use rand::Rng; use std::hash::{Hash, sip}; use std::rand::task_rng; @@ -36,14 +37,21 @@ impl<K: Clone + PartialEq + Eq + Hash, V: Clone> Cache<K,V> for HashCache<K,V> { } fn find(&mut self, key: &K) -> Option<V> { - match self.entries.find(key) { + match self.entries.get(key) { Some(v) => Some(v.clone()), None => None, } } fn find_or_create(&mut self, key: &K, blk: |&K| -> V) -> V { - self.entries.find_or_insert_with(key.clone(), blk).clone() + match self.entries.entry(key.clone()) { + Occupied(occupied) => { + (*occupied.get()).clone() + } + Vacant(vacant) => { + (*vacant.set(blk(key))).clone() + } + } } fn evict_all(&mut self) { @@ -53,7 +61,7 @@ impl<K: Clone + PartialEq + Eq + Hash, V: Clone> Cache<K,V> for HashCache<K,V> { } impl<K,V> HashCache<K,V> where K: Clone + PartialEq + Eq + Hash, V: Clone { - pub fn find_equiv<'a,Q>(&'a self, key: &Q) -> Option<&'a V> where Q: Hash + Equiv<K> { + pub fn find_equiv<'a,Sized? Q>(&'a self, key: &Q) -> Option<&'a V> where Q: Hash + Equiv<K> { self.entries.find_equiv(key) } } @@ -171,7 +179,7 @@ impl<K:Clone+PartialEq+Hash,V:Clone> SimpleHashCache<K,V> { impl<K:Clone+PartialEq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> { fn insert(&mut self, key: K, value: V) { let bucket_index = self.bucket_for_key(&key); - *self.entries.get_mut(bucket_index) = Some((key, value)); + self.entries[bucket_index] = Some((key, value)); } fn find(&mut self, key: &K) -> Option<V> { diff --git a/components/util/dlist.rs b/components/util/dlist.rs index 2abae04b047..52836786de3 100644 --- a/components/util/dlist.rs +++ b/components/util/dlist.rs @@ -24,7 +24,7 @@ struct RawNode<T> { #[unsafe_destructor] impl<T> Drop for RawDList<T> { fn drop(&mut self) { - fail!("shouldn't happen") + panic!("shouldn't happen") } } @@ -36,7 +36,7 @@ pub fn split<T>(list: &mut DList<T>) -> DList<T> { }; if list.length == 0 { - fail!("split_dlist(): empty list") + panic!("split_dlist(): empty list") } let head_node = mem::replace(&mut list.head, ptr::null_mut()); let head_list = RawDList { @@ -96,4 +96,3 @@ pub fn append_from<T>(this: &mut DList<T>, other: &mut DList<T>) { other.length = 0; } } - diff --git a/components/util/fnv.rs b/components/util/fnv.rs index a14f3ea2bec..13c8e1c28ad 100644 --- a/components/util/fnv.rs +++ b/components/util/fnv.rs @@ -19,7 +19,7 @@ pub struct FnvHasher; pub struct FnvState(u64); impl Hasher<FnvState> for FnvHasher { - fn hash<T: Hash<FnvState>>(&self, t: &T) -> u64 { + fn hash<Sized? T: Hash<FnvState>>(&self, t: &T) -> u64 { let mut state = FnvState(0xcbf29ce484222325); t.hash(&mut state); let FnvState(ret) = state; diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 64d779d1f67..8dd6d633da7 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -28,6 +28,7 @@ use std::fmt; /// /// The ratio between ScreenPx and DevicePixel for a given display be found by calling /// `servo::windowing::WindowMethods::hidpi_factor`. +#[deriving(Show)] pub enum ScreenPx {} /// One CSS "px" in the coordinate system of the "initial viewport": @@ -39,7 +40,7 @@ pub enum ScreenPx {} /// /// At the default zoom level of 100%, one PagePx is equal to one ScreenPx. However, if the /// document is zoomed in or out then this scale may be larger or smaller. -#[deriving(Encodable)] +#[deriving(Encodable, Show)] pub enum ViewportPx {} /// One CSS "px" in the root coordinate system for the content document. @@ -48,7 +49,7 @@ pub enum ViewportPx {} /// This is the mobile-style "pinch zoom" that enlarges content without reflowing it. When the /// viewport zoom is not equal to 1.0, then the layout viewport is no longer the same physical size /// as the viewable area. -#[deriving(Encodable)] +#[deriving(Encodable, Show)] pub enum PagePx {} // In summary, the hierarchy of pixel units and the factors to convert from one to the next: @@ -95,8 +96,8 @@ pub static MAX_RECT: Rect<Au> = Rect { } }; -pub static MIN_AU: Au = Au(i32::MIN); -pub static MAX_AU: Au = Au(i32::MAX); +pub const MIN_AU: Au = Au(i32::MIN); +pub const MAX_AU: Au = Au(i32::MAX); impl<E, S: Encoder<E>> Encodable<S, E> for Au { fn encode(&self, e: &mut S) -> Result<(), E> { @@ -319,4 +320,3 @@ pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> { Rect(Point2D(Au::from_frac32_px(rect.origin.x), Au::from_frac32_px(rect.origin.y)), Size2D(Au::from_frac32_px(rect.size.width), Au::from_frac32_px(rect.size.height))) } - diff --git a/components/util/lib.rs b/components/util/lib.rs index 3f4146eedfe..f556dda6eb9 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -4,13 +4,13 @@ #![feature(default_type_params,macro_rules,unsafe_destructor)] -#![deny(unused_imports, unused_variable)] +#![deny(unused_imports)] +#![deny(unused_variables)] #![feature(phase)] #[phase(plugin, link)] extern crate log; -extern crate debug; extern crate alloc; extern crate collections; extern crate geom; diff --git a/components/util/logical_geometry.rs b/components/util/logical_geometry.rs index 2faa6400e1a..fd30c6c07cb 100644 --- a/components/util/logical_geometry.rs +++ b/components/util/logical_geometry.rs @@ -12,39 +12,39 @@ use std::num::Zero; bitflags!( #[deriving(Encodable)] flags WritingMode: u8 { - static FlagRTL = 1 << 0, - static FlagVertical = 1 << 1, - static FlagVerticalLR = 1 << 2, - static FlagSidewaysLeft = 1 << 3 + const FLAG_RTL = 1 << 0, + const FLAG_VERTICAL = 1 << 1, + const FLAG_VERTICAL_LR = 1 << 2, + const FLAG_SIDEWAYS_LEFT = 1 << 3 } ) impl WritingMode { #[inline] pub fn is_vertical(&self) -> bool { - self.intersects(FlagVertical) + self.intersects(FLAG_VERTICAL) } /// Asuming .is_vertical(), does the block direction go left to right? #[inline] pub fn is_vertical_lr(&self) -> bool { - self.intersects(FlagVerticalLR) + self.intersects(FLAG_VERTICAL_LR) } /// Asuming .is_vertical(), does the inline direction go top to bottom? #[inline] pub fn is_inline_tb(&self) -> bool { - !(self.intersects(FlagSidewaysLeft) ^ self.intersects(FlagRTL)) + !(self.intersects(FLAG_SIDEWAYS_LEFT) ^ self.intersects(FLAG_RTL)) } #[inline] pub fn is_bidi_ltr(&self) -> bool { - !self.intersects(FlagRTL) + !self.intersects(FLAG_RTL) } #[inline] pub fn is_sideways_left(&self) -> bool { - self.intersects(FlagSidewaysLeft) + self.intersects(FLAG_SIDEWAYS_LEFT) } } @@ -57,7 +57,7 @@ impl Show for WritingMode { } else { try!(write!(formatter, " RL")); } - if self.intersects(FlagSidewaysLeft) { + if self.intersects(FLAG_SIDEWAYS_LEFT) { try!(write!(formatter, " SidewaysL")); } } else { diff --git a/components/util/memory.rs b/components/util/memory.rs index 2c3d92fe1d6..3dd894ebcf3 100644 --- a/components/util/memory.rs +++ b/components/util/memory.rs @@ -198,13 +198,12 @@ fn get_resident() -> Option<u64> { resident_size() } -#[cfg(not(target_os="linux"), not(target_os = "macos"))] +#[cfg(not(any(target_os="linux", target_os = "macos")))] fn get_vsize() -> Option<u64> { None } -#[cfg(not(target_os="linux"), not(target_os = "macos"))] +#[cfg(not(any(target_os="linux", target_os = "macos")))] fn get_resident() -> Option<u64> { None } - diff --git a/components/util/rtinstrument.rs b/components/util/rtinstrument.rs index f0da89d9c4a..347ed09084a 100644 --- a/components/util/rtinstrument.rs +++ b/components/util/rtinstrument.rs @@ -161,6 +161,10 @@ impl InstrumentedRuntime { } impl Runtime for InstrumentedRuntime { + fn stack_guard(&self) -> Option<uint> { + self.inner.as_ref().unwrap().stack_guard() + } + fn yield_now(mut self: Box<InstrumentedRuntime>, cur_task: Box<Task>) { self.inner.take().unwrap().yield_now(cur_task); self.put(None) diff --git a/components/util/smallvec.rs b/components/util/smallvec.rs index b8f1e62e0ae..8897ca6b313 100644 --- a/components/util/smallvec.rs +++ b/components/util/smallvec.rs @@ -5,7 +5,7 @@ //! Small vectors in various sizes. These store a certain number of elements inline and fall back //! to the heap for larger allocations. -use std::mem::init as i; +use std::mem::zeroed as i; use std::cmp; use std::fmt; use std::intrinsics; @@ -153,7 +153,7 @@ pub trait SmallVec<T> : SmallVecPrivate<T> { let last_index = self.len() - 1; if (last_index as int) < 0 { - fail!("overflow") + panic!("overflow") } let end_ptr = self.begin().offset(last_index as int); @@ -239,7 +239,7 @@ pub trait SmallVec<T> : SmallVecPrivate<T> { } fn fail_bounds_check(&self, index: uint) { - fail!("index {} beyond length ({})", index, self.len()) + panic!("index {} beyond length ({})", index, self.len()) } } diff --git a/components/util/str.rs b/components/util/str.rs index f08ae1178d9..28aedee4f30 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -71,7 +71,7 @@ pub fn split_html_space_chars<'a>(s: &'a str) -> Filter<'a, &'a str, CharSplits< fn do_parse_integer<T: Iterator<char>>(input: T) -> Option<i64> { fn is_ascii_digit(c: &char) -> bool { match *c { - '0'..'9' => true, + '0'...'9' => true, _ => false, } } @@ -152,7 +152,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto { let (mut found_full_stop, mut found_percent) = (false, false); for (i, ch) in value.chars().enumerate() { match ch { - '0'..'9' => continue, + '0'...'9' => continue, '%' => { found_percent = true; end_index = i; diff --git a/components/util/task_state.rs b/components/util/task_state.rs index 8ea42949aec..f3f72d33207 100644 --- a/components/util/task_state.rs +++ b/components/util/task_state.rs @@ -13,13 +13,13 @@ pub use self::imp::{initialize, get, enter, exit}; bitflags! { #[deriving(Show)] flags TaskState: u32 { - static Script = 0x01, - static Layout = 0x02, - static Render = 0x04, + const SCRIPT = 0x01, + const LAYOUT = 0x02, + const RENDER = 0x04, - static InWorker = 0x0100, - static InGC = 0x0200, - static InHTMLParser = 0x0400, + const IN_WORKER = 0x0100, + const IN_GC = 0x0200, + const IN_HTML_PARSER = 0x0400, } } @@ -38,9 +38,9 @@ macro_rules! task_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( )) task_types! { - is_script = Script; - is_layout = Layout; - is_render = Render; + is_script = SCRIPT; + is_layout = LAYOUT; + is_render = RENDER; } #[cfg(not(ndebug))] @@ -52,14 +52,14 @@ mod imp { pub fn initialize(x: TaskState) { match STATE.replace(Some(x)) { None => (), - Some(s) => fail!("Task state already initialized as {}", s), + Some(s) => panic!("Task state already initialized as {}", s), }; get(); // check the assertion below } pub fn get() -> TaskState { let state = match STATE.get() { - None => fail!("Task state not initialized"), + None => panic!("Task state not initialized"), Some(s) => *s, }; diff --git a/components/util/tid.rs b/components/util/tid.rs index 22fc3402dfb..1e569731ff2 100644 --- a/components/util/tid.rs +++ b/components/util/tid.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, SeqCst}; +use std::sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, SeqCst}; static mut next_tid: AtomicUint = INIT_ATOMIC_UINT; diff --git a/components/util/time.rs b/components/util/time.rs index b4a60da36ef..6c244caf141 100644 --- a/components/util/time.rs +++ b/components/util/time.rs @@ -4,7 +4,7 @@ //! Timing functions. -use collections::treemap::TreeMap; +use collections::TreeMap; use std::comm::{Sender, channel, Receiver}; use std::f64; use std::io::timer::sleep; @@ -196,7 +196,7 @@ impl TimeProfiler { } fn find_or_insert(&mut self, k: (TimeProfilerCategory, Option<TimerMetadata>), t: f64) { - match self.buckets.find_mut(&k) { + match self.buckets.get_mut(&k) { None => {}, Some(v) => { v.push(t); return; }, } diff --git a/components/util/vec.rs b/components/util/vec.rs index 61fd05fe0c5..c627448f0fc 100644 --- a/components/util/vec.rs +++ b/components/util/vec.rs @@ -4,6 +4,9 @@ use std::cmp::{PartialOrd, PartialEq}; +#[cfg(test)] +use std::fmt::Show; + /// FIXME(pcwalton): Workaround for lack of unboxed closures. This is called in /// performance-critical code, so a closure is insufficient. pub trait Comparator<K,T> { @@ -71,11 +74,11 @@ fn test_find_all_elems<T: PartialEq + PartialOrd + Eq + Ord>(arr: &[T]) { } #[cfg(test)] -fn test_miss_all_elems<T: PartialEq + PartialOrd + Eq + Ord>(arr: &[T], misses: &[T]) { +fn test_miss_all_elems<T: PartialEq + PartialOrd + Eq + Ord + Show>(arr: &[T], misses: &[T]) { let mut i = 0; while i < misses.len() { let res = arr.binary_search_(&misses[i]); - debug!("{:?} == {:?} ?", misses[i], res); + debug!("{} == {} ?", misses[i], res); assert!(!test_match(&misses[i], arr.binary_search_(&misses[i]))); i += 1; } diff --git a/components/util/workqueue.rs b/components/util/workqueue.rs index 3a041e8ce37..3420e47345b 100644 --- a/components/util/workqueue.rs +++ b/components/util/workqueue.rs @@ -14,7 +14,7 @@ use libc::funcs::posix88::unistd::usleep; use rand::{Rng, XorShiftRng}; use std::mem; use std::rand::weak_rng; -use std::sync::atomics::{AtomicUint, SeqCst}; +use std::sync::atomic::{AtomicUint, SeqCst}; use std::sync::deque::{Abort, BufferPool, Data, Empty, Stealer, Worker}; /// A unit of work. @@ -82,7 +82,7 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { // Wait for a start message. let (mut deque, ref_count, queue_data) = match self.port.recv() { StartMsg(deque, ref_count, queue_data) => (deque, ref_count, queue_data), - StopMsg => fail!("unexpected stop message"), + StopMsg => panic!("unexpected stop message"), ExitMsg => return, }; @@ -105,7 +105,7 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { let mut should_continue = true; loop { let victim = (self.rng.next_u32() as uint) % self.other_deques.len(); - match self.other_deques.get_mut(victim).steal() { + match self.other_deques[victim].steal() { Empty | Abort => { // Continue. } @@ -130,7 +130,7 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { break } Ok(ExitMsg) => return, - Ok(_) => fail!("unexpected message"), + Ok(_) => panic!("unexpected message"), _ => {} } @@ -239,7 +239,7 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { for i in range(0, thread_count) { for j in range(0, thread_count) { if i != j { - threads.get_mut(i).other_deques.push(infos[j].thief.clone()) + threads[i].other_deques.push(infos[j].thief.clone()) } } assert!(threads[i].other_deques.len() == thread_count - 1) @@ -251,7 +251,7 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { spawn_named_native( format!("{} worker {}/{}", task_name, i+1, thread_count), proc() { - task_state::initialize(state | task_state::InWorker); + task_state::initialize(state | task_state::IN_WORKER); let mut thread = thread; thread.start() }) @@ -268,9 +268,10 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { /// Enqueues a block into the work queue. #[inline] pub fn push(&mut self, work_unit: WorkUnit<QueueData, WorkData>) { - match self.workers.get_mut(0).deque { + let deque = &mut self.workers[0].deque; + match *deque { None => { - fail!("tried to push a block but we don't have the deque?!") + panic!("tried to push a block but we don't have the deque?!") } Some(ref mut deque) => deque.push(work_unit), } @@ -297,8 +298,8 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> { // Get our deques back. for _ in range(0, self.workers.len()) { match self.port.recv() { - ReturnDequeMsg(index, deque) => self.workers.get_mut(index).deque = Some(deque), - FinishedMsg => fail!("unexpected finished message!"), + ReturnDequeMsg(index, deque) => self.workers[index].deque = Some(deque), + FinishedMsg => panic!("unexpected finished message!"), } } } |