aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/util
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-03-19 12:35:17 -0400
committerbors-servo <release+servo@mozilla.com>2014-03-19 12:35:17 -0400
commitf7aa6e3d9b8bfcc0565624f1094241b3b8658bd8 (patch)
tree7e7fbd7976c3da12ff463d6ffbeb1a3a336ae7d3 /src/components/util
parentcaf1ed94468da3c134cc8e8f4a1b934bb353dc19 (diff)
parenta6100563a6e43471ae43fb155113bc2026992f78 (diff)
downloadservo-f7aa6e3d9b8bfcc0565624f1094241b3b8658bd8.tar.gz
servo-f7aa6e3d9b8bfcc0565624f1094241b3b8658bd8.zip
auto merge of #1934 : larsbergstrom/servo/rust_20140224_squashed, r=jdm
For review only - don't approve yet (need to squash and land submodule updates first). critic? @metajack
Diffstat (limited to 'src/components/util')
-rw-r--r--src/components/util/cache.rs32
-rw-r--r--src/components/util/concurrentmap.rs51
-rw-r--r--src/components/util/debug.rs12
-rw-r--r--src/components/util/geometry.rs134
-rw-r--r--src/components/util/io.rs20
-rw-r--r--src/components/util/opts.rs38
-rw-r--r--src/components/util/range.rs6
-rw-r--r--src/components/util/smallvec.rs32
-rw-r--r--src/components/util/task.rs14
-rw-r--r--src/components/util/time.rs29
-rw-r--r--src/components/util/url.rs2
-rw-r--r--src/components/util/util.rs14
-rw-r--r--src/components/util/vec.rs6
-rw-r--r--src/components/util/workqueue.rs17
14 files changed, 231 insertions, 176 deletions
diff --git a/src/components/util/cache.rs b/src/components/util/cache.rs
index dcdb3259c25..3eb37145df7 100644
--- a/src/components/util/cache.rs
+++ b/src/components/util/cache.rs
@@ -2,12 +2,16 @@
* 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::hashmap::HashMap;
+use collections::HashMap;
+use std::hash::{Hash, sip};
use std::rand::Rng;
use std::rand;
-use std::vec::VecIterator;
+use std::vec::Items;
use std::vec;
+#[cfg(test)]
+use std::cell::Cell;
+
pub trait Cache<K: Eq, V: Clone> {
fn insert(&mut self, key: K, value: V);
fn find(&mut self, key: &K) -> Option<V>;
@@ -56,8 +60,8 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for MonoCache<K,V> {
#[test]
fn test_monocache() {
let mut cache = MonoCache::new(10);
- let one = @"one";
- let two = @"two";
+ let one = Cell::new("one");
+ let two = Cell::new("two");
cache.insert(1, one);
assert!(cache.find(&1).is_some());
@@ -103,8 +107,8 @@ impl<K: Clone + Eq + Hash, V: Clone> Cache<K,V> for HashCache<K,V> {
#[test]
fn test_hashcache() {
let mut cache = HashCache::new();
- let one = @"one";
- let two = @"two";
+ let one = Cell::new("one");
+ let two = Cell::new("two");
cache.insert(1, one);
assert!(cache.find(&1).is_some());
@@ -133,12 +137,12 @@ impl<K: Clone + Eq, V: Clone> LRUCache<K,V> {
let last_index = self.entries.len() - 1;
if pos != last_index {
let entry = self.entries.remove(pos);
- self.entries.push(entry);
+ self.entries.push(entry.unwrap());
}
- self.entries[last_index].second_ref().clone()
+ self.entries[last_index].ref1().clone()
}
- pub fn iter<'a>(&'a self) -> VecIterator<'a,(K,V)> {
+ pub fn iter<'a>(&'a self) -> Items<'a,(K,V)> {
self.entries.iter()
}
}
@@ -197,7 +201,7 @@ impl<K:Clone+Eq+Hash,V:Clone> SimpleHashCache<K,V> {
#[inline]
fn bucket_for_key<Q:Hash>(&self, key: &Q) -> uint {
- self.to_bucket(key.hash_keyed(self.k0, self.k1) as uint)
+ self.to_bucket(sip::hash_with_keys(self.k0, self.k1, key) as uint)
}
#[inline]
@@ -243,10 +247,10 @@ impl<K:Clone+Eq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> {
#[test]
fn test_lru_cache() {
- let one = @"one";
- let two = @"two";
- let three = @"three";
- let four = @"four";
+ let one = Cell::new("one");
+ let two = Cell::new("two");
+ let three = Cell::new("three");
+ let four = Cell::new("four");
// Test normal insertion.
let mut cache = LRUCache::new(2); // (_, _) (cache is empty)
diff --git a/src/components/util/concurrentmap.rs b/src/components/util/concurrentmap.rs
index 08d60b79284..a4ca68706b1 100644
--- a/src/components/util/concurrentmap.rs
+++ b/src/components/util/concurrentmap.rs
@@ -5,12 +5,13 @@
//! A Doug Lea-style concurrent hash map using striped locks.
use std::cast;
+use std::hash::{Hash, sip};
use std::ptr;
use std::rand::Rng;
use std::rand;
use std::sync::atomics::{AtomicUint, Relaxed, SeqCst};
-use std::unstable::mutex::Mutex;
-use std::util;
+use std::unstable::mutex::StaticNativeMutex;
+use std::mem;
use std::vec;
/// When the size exceeds (number of buckets * LOAD_NUMERATOR/LOAD_DENOMINATOR), the hash table
@@ -37,7 +38,7 @@ pub struct ConcurrentHashMap<K,V> {
/// The number of elements in this hash table.
priv size: AtomicUint,
/// The striped locks.
- priv locks: ~[Mutex],
+ priv locks: ~[StaticNativeMutex],
/// The buckets.
priv buckets: ~[Option<Bucket<K,V>>],
}
@@ -58,7 +59,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
size: AtomicUint::new(0),
locks: vec::from_fn(lock_count, |_| {
unsafe {
- Mutex::new()
+ StaticNativeMutex::new()
}
}),
buckets: vec::from_fn(lock_count * buckets_per_lock, |_| None),
@@ -74,7 +75,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
loop {
let (bucket_index, lock_index) = self.bucket_and_lock_indices(&key);
if this.overloaded() {
- this.locks[lock_index].unlock();
+ this.locks[lock_index].unlock_noguard();
this.try_resize(self.buckets_per_lock() * 2);
// Have to retry because the bucket and lock indices will have shifted.
@@ -82,7 +83,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
}
this.insert_unlocked(key, value, Some(bucket_index));
- this.locks[lock_index].unlock();
+ this.locks[lock_index].unlock_noguard();
break
}
}
@@ -118,7 +119,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
match (*bucket).next {
None => {}
Some(ref mut next_bucket) => {
- bucket = ptr::to_mut_unsafe_ptr(&mut **next_bucket);
+ bucket = &mut **next_bucket as *mut Bucket<K,V>;
continue
}
}
@@ -150,7 +151,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
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 = util::replace(&mut bucket.next, None);
+ let next_opt = mem::replace(&mut bucket.next, None);
match next_opt {
None => nuke_bucket = true,
Some(~next) => *bucket = next,
@@ -168,7 +169,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
Some(ref mut bucket) => {
// Continue the search.
if bucket.key != *key {
- prev = ptr::to_mut_unsafe_ptr(&mut **bucket);
+ prev = &mut **bucket as *mut Bucket<K,V>;
continue
}
}
@@ -191,7 +192,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
}
unsafe {
- this.locks[lock_index].unlock()
+ this.locks[lock_index].unlock_noguard()
}
}
@@ -235,7 +236,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
}
unsafe {
- this.locks[lock_index].unlock()
+ this.locks[lock_index].unlock_noguard()
}
result
@@ -255,7 +256,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
stripe_index += 1;
if stripe_index == buckets_per_lock {
unsafe {
- this.locks[lock_index].unlock();
+ this.locks[lock_index].unlock_noguard();
}
stripe_index = 0;
@@ -263,7 +264,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
}
if stripe_index == 0 {
unsafe {
- this.locks[lock_index].lock()
+ this.locks[lock_index].lock_noguard()
}
}
@@ -284,7 +285,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
// Take a lock on all buckets.
for lock in this.locks.mut_iter() {
unsafe {
- lock.lock()
+ lock.lock_noguard()
}
}
@@ -295,7 +296,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
if new_bucket_count > this.buckets.len() {
// Create a new set of buckets.
let mut buckets = vec::from_fn(new_bucket_count, |_| None);
- util::swap(&mut this.buckets, &mut buckets);
+ mem::swap(&mut this.buckets, &mut buckets);
this.size.store(0, Relaxed);
// Go through all the old buckets and insert the new data.
@@ -335,7 +336,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
// Release all our locks.
for lock in this.locks.mut_iter() {
unsafe {
- lock.unlock()
+ lock.unlock_noguard()
}
}
}
@@ -346,10 +347,10 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
#[inline]
fn bucket_and_lock_indices(&self, key: &K) -> (uint, uint) {
let this: &mut ConcurrentHashMap<K,V> = unsafe {
- cast::transmute_mut(self)
+ cast::transmute_mut(cast::transmute_region(self))
};
- let hash = key.hash_keyed(self.k0, self.k1);
+ let hash = sip::hash_with_keys(self.k0, self.k1, key);
let lock_count = this.locks.len();
let mut bucket_index;
let mut lock_index;
@@ -359,7 +360,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
bucket_index = hash as uint % bucket_count;
lock_index = bucket_index / buckets_per_lock;
unsafe {
- this.locks[lock_index].lock();
+ this.locks[lock_index].lock_noguard();
}
let new_bucket_count = this.buckets.len();
if bucket_count == new_bucket_count {
@@ -368,7 +369,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
// If we got here, the hash table resized from under us: try again.
unsafe {
- this.locks[lock_index].unlock()
+ this.locks[lock_index].unlock_noguard()
}
}
@@ -379,7 +380,7 @@ impl<K:Hash + Eq,V> ConcurrentHashMap<K,V> {
/// function!
#[inline]
unsafe fn bucket_index_unlocked(&self, key: &K) -> uint {
- let hash = key.hash_keyed(self.k0, self.k1);
+ let hash = sip::hash_with_keys(self.k0, self.k1, key);
hash as uint % self.buckets.len()
}
@@ -446,12 +447,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].unlock()
+ map.locks[lock_index].unlock_noguard()
}
}
if bucket_index != (bucket_count as int) - 1 {
unsafe {
- map.locks[lock_index + 1].lock()
+ map.locks[lock_index + 1].lock_noguard()
}
}
}
@@ -481,7 +482,7 @@ impl<'a,K,V> Iterator<(&'a K, &'a V)> for ConcurrentHashMapIterator<'a,K,V> {
#[cfg(test)]
pub mod test {
- use extra::arc::Arc;
+ use sync::Arc;
use native;
use concurrentmap::ConcurrentHashMap;
@@ -489,7 +490,7 @@ pub mod test {
#[test]
pub fn smoke() {
let m = Arc::new(ConcurrentHashMap::new());
- let (port, chan) = SharedChan::new();
+ let (port, chan) = Chan::new();
// Big enough to make it resize once.
for i in range(0, 5) {
diff --git a/src/components/util/debug.rs b/src/components/util/debug.rs
index 029db75d129..0cebc305a27 100644
--- a/src/components/util/debug.rs
+++ b/src/components/util/debug.rs
@@ -10,18 +10,18 @@ use std::mem::size_of;
fn hexdump_slice(buf: &[u8]) {
let mut stderr = io::stderr();
- stderr.write(bytes!(" "));
+ stderr.write(bytes!(" ")).unwrap();
for (i, &v) in buf.iter().enumerate() {
let output = format!("{:02X} ", v as uint);
- stderr.write(output.as_bytes());
+ stderr.write(output.as_bytes()).unwrap();
match i % 16 {
- 15 => stderr.write(bytes!("\n ")),
- 7 => stderr.write(bytes!(" ")),
+ 15 => { stderr.write(bytes!("\n ")).unwrap(); },
+ 7 => { stderr.write(bytes!(" ")).unwrap(); },
_ => ()
}
- stderr.flush();
+ stderr.flush().unwrap();
}
- stderr.write(bytes!("\n"));
+ stderr.write(bytes!("\n")).unwrap();
}
pub fn hexdump<T>(obj: &T) {
diff --git a/src/components/util/geometry.rs b/src/components/util/geometry.rs
index 4935c802d9b..e02bb8a6bb9 100644
--- a/src/components/util/geometry.rs
+++ b/src/components/util/geometry.rs
@@ -18,67 +18,111 @@ pub struct Au(i32);
impl Clone for Au {
#[inline]
fn clone(&self) -> Au {
- Au(**self)
+ let Au(i) = *self;
+ Au(i)
}
}
-impl fmt::Default for Au {
- fn fmt(obj: &Au, f: &mut fmt::Formatter) {
- let Au(n) = *obj;
- write!(f.buf, "Au({})", n);
- }
-}
+impl fmt::Show for Au {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let Au(n) = *self;
+ write!(f.buf, "Au({})", n)
+ }}
impl Eq for Au {
#[inline]
fn eq(&self, other: &Au) -> bool {
- **self == **other
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s == o
}
#[inline]
fn ne(&self, other: &Au) -> bool {
- **self != **other
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s != o
}
}
impl Add<Au,Au> for Au {
#[inline]
- fn add(&self, other: &Au) -> Au { Au(**self + **other) }
+ fn add(&self, other: &Au) -> Au {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ Au(s + o)
+ }
}
impl Sub<Au,Au> for Au {
#[inline]
- fn sub(&self, other: &Au) -> Au { Au(**self - **other) }
+ fn sub(&self, other: &Au) -> Au {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ Au(s - o)
+ }
+
}
impl Mul<Au,Au> for Au {
#[inline]
- fn mul(&self, other: &Au) -> Au { Au(**self * **other) }
+ fn mul(&self, other: &Au) -> Au {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ Au(s * o)
+ }
}
impl Div<Au,Au> for Au {
#[inline]
- fn div(&self, other: &Au) -> Au { Au(**self / **other) }
+ fn div(&self, other: &Au) -> Au {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ Au(s / o)
+ }
}
impl Rem<Au,Au> for Au {
#[inline]
- fn rem(&self, other: &Au) -> Au { Au(**self % **other) }
+ fn rem(&self, other: &Au) -> Au {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ Au(s % o)
+ }
}
impl Neg<Au> for Au {
#[inline]
- fn neg(&self) -> Au { Au(-**self) }
+ fn neg(&self) -> Au {
+ let Au(s) = *self;
+ Au(-s)
+ }
}
impl Ord for Au {
#[inline]
- fn lt(&self, other: &Au) -> bool { **self < **other }
+ fn lt(&self, other: &Au) -> bool {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s < o
+ }
#[inline]
- fn le(&self, other: &Au) -> bool { **self <= **other }
+ fn le(&self, other: &Au) -> bool {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s <= o
+ }
#[inline]
- fn ge(&self, other: &Au) -> bool { **self >= **other }
+ fn ge(&self, other: &Au) -> bool {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s >= o
+ }
#[inline]
- fn gt(&self, other: &Au) -> bool { **self > **other }
+ fn gt(&self, other: &Au) -> bool {
+ let Au(s) = *self;
+ let Au(o) = *other;
+ s > o
+ }
}
impl One for Au {
@@ -90,7 +134,10 @@ impl Zero for Au {
#[inline]
fn zero() -> Au { Au(0) }
#[inline]
- fn is_zero(&self) -> bool { **self == 0 }
+ fn is_zero(&self) -> bool {
+ let Au(s) = *self;
+ s == 0
+ }
}
impl Num for Au {}
@@ -110,22 +157,26 @@ impl NumCast for Au {
impl ToPrimitive for Au {
#[inline]
fn to_i64(&self) -> Option<i64> {
- Some(**self as i64)
+ let Au(s) = *self;
+ Some(s as i64)
}
#[inline]
fn to_u64(&self) -> Option<u64> {
- Some(**self as u64)
+ let Au(s) = *self;
+ Some(s as u64)
}
#[inline]
fn to_f32(&self) -> Option<f32> {
- (**self).to_f32()
+ let Au(s) = *self;
+ s.to_f32()
}
#[inline]
fn to_f64(&self) -> Option<f64> {
- (**self).to_f64()
+ let Au(s) = *self;
+ s.to_f64()
}
}
@@ -138,7 +189,8 @@ impl Au {
#[inline]
pub fn scale_by(self, factor: f64) -> Au {
- Au(((*self as f64) * factor) as i32)
+ let Au(s) = self;
+ Au(((s as f64) * factor) as i32)
}
#[inline]
@@ -148,14 +200,16 @@ impl Au {
#[inline]
pub fn to_nearest_px(&self) -> int {
- ((**self as f64) / 60f64).round() as int
+ let Au(s) = *self;
+ ((s as f64) / 60f64).round() as int
}
#[inline]
pub fn to_snapped(&self) -> Au {
- let res = **self % 60i32;
- return if res >= 30i32 { return Au(**self - res + 60i32) }
- else { return Au(**self - res) };
+ let Au(s) = *self;
+ let res = s % 60i32;
+ return if res >= 30i32 { return Au(s - res + 60i32) }
+ else { return Au(s - res) };
}
#[inline]
@@ -180,9 +234,18 @@ impl Au {
}
#[inline]
- pub fn min(x: Au, y: Au) -> Au { if *x < *y { x } else { y } }
+ pub fn min(x: Au, y: Au) -> Au {
+ let Au(xi) = x;
+ let Au(yi) = y;
+ if xi < yi { x } else { y }
+ }
+
#[inline]
- pub fn max(x: Au, y: Au) -> Au { if *x > *y { x } else { y } }
+ pub fn max(x: Au, y: Au) -> Au {
+ let Au(xi) = x;
+ let Au(yi) = y;
+ if xi > yi { x } else { y }
+ }
}
// assumes 72 points per inch, and 96 px per inch
@@ -217,11 +280,13 @@ pub fn from_px(px: int) -> Au {
}
pub fn to_px(au: Au) -> int {
- (*au / 60) as int
+ let Au(a) = au;
+ (a / 60) as int
}
pub fn to_frac_px(au: Au) -> f64 {
- (*au as f64) / 60f64
+ let Au(a) = au;
+ (a as f64) / 60f64
}
// assumes 72 points per inch, and 96 px per inch
@@ -231,6 +296,7 @@ pub fn from_pt(pt: f64) -> Au {
// assumes 72 points per inch, and 96 px per inch
pub fn to_pt(au: Au) -> f64 {
- (*au as f64) / 60f64 * 72f64 / 96f64
+ let Au(a) = au;
+ (a as f64) / 60f64 * 72f64 / 96f64
}
diff --git a/src/components/util/io.rs b/src/components/util/io.rs
deleted file mode 100644
index b034682cf16..00000000000
--- a/src/components/util/io.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * 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::io::{io_error, IoError};
-
-/// Helper for catching an I/O error and wrapping it in a Result object. The
-/// return result will be the last I/O error that happened or the result of the
-/// closure if no error occurred.
-///
-/// FIXME: This is a copy of std::rt::io::result which doesn't exist yet in our
-/// version of Rust. We should switch after the next Rust upgrade.
-pub fn result<T>(cb: || -> T) -> Result<T, IoError> {
- let mut err = None;
- let ret = io_error::cond.trap(|e| err = Some(e)).inside(cb);
- match err {
- Some(e) => Err(e),
- None => Ok(ret),
- }
-}
diff --git a/src/components/util/opts.rs b/src/components/util/opts.rs
index e33d5b87379..668dc4be429 100644
--- a/src/components/util/opts.rs
+++ b/src/components/util/opts.rs
@@ -7,8 +7,8 @@
use azure::azure_hl::{BackendType, CairoBackend, CoreGraphicsBackend};
use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBackend};
-use extra::getopts::groups;
-use std::num;
+use getopts;
+use std::cmp;
use std::rt;
use std::io;
use std::os;
@@ -56,13 +56,13 @@ pub struct Opts {
bubble_widths_separately: bool,
}
-fn print_usage(app: &str, opts: &[groups::OptGroup]) {
+fn print_usage(app: &str, opts: &[getopts::OptGroup]) {
let message = format!("Usage: {} [ options ... ] [URL]\n\twhere options include", app);
- println(groups::usage(message, opts));
+ println!("{}", getopts::usage(message, opts));
}
fn args_fail(msg: &str) {
- io::stderr().write_line(msg);
+ io::stderr().write_line(msg).unwrap();
os::set_exit_status(1);
}
@@ -71,21 +71,21 @@ pub fn from_cmdline_args(args: &[~str]) -> Option<Opts> {
let args = args.tail();
let opts = ~[
- groups::optflag("c", "cpu", "CPU rendering"),
- groups::optopt("o", "output", "Output file", "output.png"),
- groups::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
- groups::optopt("s", "size", "Size of tiles", "512"),
- groups::optopt("t", "threads", "Number of render threads", "1"),
- groups::optflagopt("p", "profile", "Profiler flag and output interval", "10"),
- groups::optflag("x", "exit", "Exit after load flag"),
- groups::optopt("y", "layout-threads", "Number of threads to use for layout", "1"),
- groups::optflag("z", "headless", "Headless mode"),
- groups::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"),
- groups::optflag("b", "bubble-widths", "Bubble intrinsic widths separately like other engines"),
- groups::optflag("h", "help", "Print this message")
+ getopts::optflag("c", "cpu", "CPU rendering"),
+ getopts::optopt("o", "output", "Output file", "output.png"),
+ getopts::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
+ getopts::optopt("s", "size", "Size of tiles", "512"),
+ getopts::optopt("t", "threads", "Number of render threads", "1"),
+ getopts::optflagopt("p", "profile", "Profiler flag and output interval", "10"),
+ getopts::optflag("x", "exit", "Exit after load flag"),
+ getopts::optopt("y", "layout-threads", "Number of threads to use for layout", "1"),
+ getopts::optflag("z", "headless", "Headless mode"),
+ getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"),
+ getopts::optflag("b", "bubble-widths", "Bubble intrinsic widths separately like other engines"),
+ getopts::optflag("h", "help", "Print this message")
];
- let opt_match = match groups::getopts(args, opts) {
+ let opt_match = match getopts::getopts(args, opts) {
Ok(m) => m,
Err(f) => {
args_fail(f.to_err_msg());
@@ -144,7 +144,7 @@ pub fn from_cmdline_args(args: &[~str]) -> Option<Opts> {
let layout_threads: uint = match opt_match.opt_str("y") {
Some(layout_threads_str) => from_str(layout_threads_str).unwrap(),
- None => num::max(rt::default_sched_threads() * 3 / 4, 1),
+ None => cmp::max(rt::default_sched_threads() * 3 / 4, 1),
};
Some(Opts {
diff --git a/src/components/util/range.rs b/src/components/util/range.rs
index c256ce3d1c8..59e29876909 100644
--- a/src/components/util/range.rs
+++ b/src/components/util/range.rs
@@ -22,9 +22,9 @@ pub struct Range {
priv len: uint
}
-impl fmt::Default for Range {
- fn fmt(obj: &Range, f: &mut fmt::Formatter) {
- write!(f.buf, "[{} .. {})", obj.begin(), obj.end());
+impl fmt::Show for Range {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f.buf, "[{} .. {})", self.begin(), self.end())
}
}
diff --git a/src/components/util/smallvec.rs b/src/components/util/smallvec.rs
index cd96ce9b573..ab51fd961f1 100644
--- a/src/components/util/smallvec.rs
+++ b/src/components/util/smallvec.rs
@@ -5,17 +5,15 @@
//! Small vectors in various sizes. These store a certain number of elements inline and fall back
//! to the heap for larger allocations.
-use i = std::unstable::intrinsics::init;
+use i = std::mem::init;
use std::cast;
-use std::libc::c_char;
+use std::cmp;
+use std::intrinsics;
use std::mem;
-use std::num;
use std::ptr;
use std::rt::global_heap;
use std::rt::local_heap;
-use std::unstable::intrinsics;
-use std::unstable::raw::Slice;
-use std::util;
+use std::raw::Slice;
// Generic code for all small vectors
@@ -86,11 +84,11 @@ pub trait SmallVec<T> : SmallVecPrivate<T> {
fn push(&mut self, value: T) {
let cap = self.cap();
if self.len() == cap {
- self.grow(num::max(cap * 2, 1))
+ self.grow(cmp::max(cap * 2, 1))
}
unsafe {
let end: &mut T = cast::transmute(self.end());
- intrinsics::move_val_init(end, value);
+ mem::move_val_init(end, value);
let len = self.len();
self.set_len(len + 1)
}
@@ -104,9 +102,9 @@ pub trait SmallVec<T> : SmallVecPrivate<T> {
if self.spilled() {
if intrinsics::owns_managed::<T>() {
- local_heap::local_free(self.ptr() as *u8 as *c_char)
+ local_heap::local_free(self.ptr() as *u8)
} else {
- global_heap::exchange_free(self.ptr() as *u8 as *c_char)
+ global_heap::exchange_free(self.ptr() as *u8)
}
} else {
let mut_begin: *mut T = cast::transmute(self.begin());
@@ -211,7 +209,7 @@ impl<'a,T> Iterator<T> for SmallVecMoveIterator<'a,T> {
Some(reference) => {
// Zero out the values as we go so they don't get double-freed.
let reference: &mut T = cast::transmute(reference);
- Some(util::replace(reference, intrinsics::init()))
+ Some(mem::replace(reference, mem::init()))
}
}
}
@@ -229,9 +227,9 @@ impl<'a,T> Drop for SmallVecMoveIterator<'a,T> {
Some(allocation) => {
unsafe {
if intrinsics::owns_managed::<T>() {
- local_heap::local_free(allocation as *u8 as *c_char)
+ local_heap::local_free(allocation as *u8)
} else {
- global_heap::exchange_free(allocation as *u8 as *c_char)
+ global_heap::exchange_free(allocation as *u8)
}
}
}
@@ -310,13 +308,13 @@ macro_rules! def_small_vector_drop_impl(
unsafe {
let ptr = self.mut_ptr();
for i in range(0, self.len()) {
- *ptr.offset(i as int) = intrinsics::uninit();
+ *ptr.offset(i as int) = mem::uninit();
}
if intrinsics::owns_managed::<T>() {
- local_heap::local_free(self.ptr() as *u8 as *c_char)
+ local_heap::local_free(self.ptr() as *u8)
} else {
- global_heap::exchange_free(self.ptr() as *u8 as *c_char)
+ global_heap::exchange_free(self.ptr() as *u8)
}
}
}
@@ -348,7 +346,7 @@ macro_rules! def_small_vector_impl(
len: 0,
cap: $size,
ptr: ptr::null(),
- data: intrinsics::init(),
+ data: mem::init(),
}
}
}
diff --git a/src/components/util/task.rs b/src/components/util/task.rs
index 49b22348dfa..e487c0b26fa 100644
--- a/src/components/util/task.rs
+++ b/src/components/util/task.rs
@@ -2,24 +2,24 @@
* 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::str::IntoMaybeOwned;
use std::task;
-use std::comm::SharedChan;
+use std::comm::Chan;
use std::task::TaskBuilder;
-pub fn spawn_named<S: IntoSendStr>(name: S, f: proc()) {
- let mut builder = task::task();
- builder.name(name);
+pub fn spawn_named<S: IntoMaybeOwned<'static>>(name: S, f: proc()) {
+ let builder = task::task().named(name);
builder.spawn(f);
}
/// Arrange to send a particular message to a channel if the task built by
/// this `TaskBuilder` fails.
-pub fn send_on_failure<T: Send>(builder: &mut TaskBuilder, msg: T, dest: SharedChan<T>) {
+pub fn send_on_failure<T: Send>(builder: &mut TaskBuilder, msg: T, dest: Chan<T>) {
let port = builder.future_result();
- do spawn {
+ spawn(proc() {
match port.recv() {
Ok(()) => (),
Err(..) => dest.send(msg),
}
- }
+ })
}
diff --git a/src/components/util/time.rs b/src/components/util/time.rs
index 4a5095eb33c..41325e9bb69 100644
--- a/src/components/util/time.rs
+++ b/src/components/util/time.rs
@@ -4,9 +4,9 @@
//! Timing functions.
-use extra::time::precise_time_ns;
-use extra::treemap::TreeMap;
-use std::comm::{Port, SharedChan};
+use std_time::precise_time_ns;
+use collections::treemap::TreeMap;
+use std::comm::{Port, Chan};
use std::iter::AdditiveIterator;
use task::{spawn_named};
@@ -28,11 +28,12 @@ impl Timer {
// front-end representation of the profiler used to communicate with the profiler
#[deriving(Clone)]
-pub struct ProfilerChan(SharedChan<ProfilerMsg>);
+pub struct ProfilerChan(Chan<ProfilerMsg>);
impl ProfilerChan {
pub fn send(&self, msg: ProfilerMsg) {
- (**self).send(msg);
+ let ProfilerChan(ref c) = *self;
+ c.send(msg);
}
}
@@ -123,7 +124,7 @@ pub struct Profiler {
impl Profiler {
pub fn create(period: Option<f64>) -> ProfilerChan {
- let (port, chan) = SharedChan::new();
+ let (port, chan) = Chan::new();
match period {
Some(period) => {
let period = (period * 1000f64) as u64;
@@ -195,9 +196,9 @@ impl Profiler {
}
fn print_buckets(&mut self) {
- println(format!("{:39s} {:15s} {:15s} {:15s} {:15s} {:15s}",
- "_category_", "_mean (ms)_", "_median (ms)_",
- "_min (ms)_", "_max (ms)_", "_bucket size_"));
+ println!("{:39s} {:15s} {:15s} {:15s} {:15s} {:15s}",
+ "_category_", "_mean (ms)_", "_median (ms)_",
+ "_min (ms)_", "_max (ms)_", "_bucket size_");
for (category, data) in self.buckets.iter() {
// FIXME(XXX): TreeMap currently lacks mut_iter()
let mut data = data.clone();
@@ -215,11 +216,11 @@ impl Profiler {
data[data_len / 2],
data.iter().min().unwrap(),
data.iter().max().unwrap());
- println(format!("{:-35s}: {:15.4f} {:15.4f} {:15.4f} {:15.4f} {:15u}",
- category.format(), mean, median, min, max, data_len));
+ println!("{:-35s}: {:15.4f} {:15.4f} {:15.4f} {:15.4f} {:15u}",
+ category.format(), mean, median, min, max, data_len);
}
}
- println("");
+ println!("");
}
}
@@ -231,7 +232,7 @@ pub fn profile<T>(category: ProfilerCategory,
let start_time = precise_time_ns();
let val = callback();
let end_time = precise_time_ns();
- let ms = ((end_time - start_time) as f64 / 1000000f64);
+ let ms = (end_time - start_time) as f64 / 1000000f64;
profiler_chan.send(TimeMsg(category, ms));
return val;
}
@@ -240,7 +241,7 @@ pub fn time<T>(msg: &str, callback: || -> T) -> T{
let start_time = precise_time_ns();
let val = callback();
let end_time = precise_time_ns();
- let ms = ((end_time - start_time) as f64 / 1000000f64);
+ let ms = (end_time - start_time) as f64 / 1000000f64;
if ms >= 5f64 {
debug!("{:s} took {} ms", msg, ms);
}
diff --git a/src/components/util/url.rs b/src/components/util/url.rs
index 004d72e48b8..dafacbc55e4 100644
--- a/src/components/util/url.rs
+++ b/src/components/util/url.rs
@@ -4,7 +4,7 @@
use extra::url;
use extra::url::Url;
-use std::hashmap::HashMap;
+use collections::HashMap;
use std::os;
/**
diff --git a/src/components/util/util.rs b/src/components/util/util.rs
index 9df491dfeb5..f07fc0b6b2c 100644
--- a/src/components/util/util.rs
+++ b/src/components/util/util.rs
@@ -7,17 +7,21 @@
#[feature(macro_rules, managed_boxes)];
-extern mod azure;
-extern mod extra;
-extern mod geom;
-extern mod native;
+extern crate azure;
+extern crate collections;
+extern crate extra;
+extern crate geom;
+extern crate getopts;
+extern crate native;
+extern crate serialize;
+extern crate sync;
+extern crate std_time = "time";
pub mod cache;
pub mod concurrentmap;
pub mod cowarc;
pub mod debug;
pub mod geometry;
-pub mod io;
pub mod namespace;
pub mod opts;
pub mod range;
diff --git a/src/components/util/vec.rs b/src/components/util/vec.rs
index 2c525c701cc..2fabf8455ef 100644
--- a/src/components/util/vec.rs
+++ b/src/components/util/vec.rs
@@ -22,14 +22,14 @@ impl<'a, T: Ord + Eq> BinarySearchMethods<'a, T> for &'a [T] {
let mut low : int = 0;
let mut high : int = (self.len() as int) - 1;
- while (low <= high) {
+ while low <= high {
// http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
let mid : int = (((low as uint) + (high as uint)) >> 1) as int;
let midv = &self[mid];
- if (midv < key) {
+ if midv < key {
low = mid + 1;
- } else if (midv > key) {
+ } else if midv > key {
high = mid - 1;
} else {
return Some(mid as uint);
diff --git a/src/components/util/workqueue.rs b/src/components/util/workqueue.rs
index 0254b0c573f..93ea740c5a0 100644
--- a/src/components/util/workqueue.rs
+++ b/src/components/util/workqueue.rs
@@ -9,11 +9,12 @@
use native;
use std::cast;
+use std::comm;
+use std::mem;
use std::rand::{Rng, XorShiftRng};
use std::rand;
use std::sync::atomics::{AtomicUint, SeqCst};
use std::sync::deque::{Abort, BufferPool, Data, Empty, Stealer, Worker};
-use std::unstable::intrinsics;
/// A unit of work.
///
@@ -64,7 +65,7 @@ struct WorkerThread<QUD,WUD> {
/// The communication port from the supervisor.
port: Port<WorkerMsg<QUD,WUD>>,
/// The communication channel on which messages are sent to the supervisor.
- chan: SharedChan<SupervisorMsg<QUD,WUD>>,
+ chan: Chan<SupervisorMsg<QUD,WUD>>,
/// The thief end of the work-stealing deque for all other workers.
other_deques: ~[Stealer<WorkUnit<QUD,WUD>>],
/// The random number generator for this worker.
@@ -92,7 +93,7 @@ impl<QUD:Send,WUD:Send> WorkerThread<QUD,WUD> {
// FIXME(pcwalton): Nasty workaround for the lack of labeled break/continue
// cross-crate.
let mut work_unit = unsafe {
- intrinsics::uninit()
+ mem::uninit()
};
match deque.pop() {
Some(work) => work_unit = work,
@@ -114,13 +115,13 @@ impl<QUD:Send,WUD:Send> WorkerThread<QUD,WUD> {
if i == SPIN_COUNT {
match self.port.try_recv() {
- Some(StopMsg) => {
+ comm::Data(StopMsg) => {
should_continue = false;
break
}
- Some(ExitMsg) => return,
- Some(_) => fail!("unexpected message"),
- None => {}
+ comm::Data(ExitMsg) => return,
+ comm::Data(_) => fail!("unexpected message"),
+ _ => {}
}
i = 0
@@ -201,7 +202,7 @@ impl<QUD:Send,WUD:Send> WorkQueue<QUD,WUD> {
/// it.
pub fn new(thread_count: uint, user_data: QUD) -> WorkQueue<QUD,WUD> {
// Set up data structures.
- let (supervisor_port, supervisor_chan) = SharedChan::new();
+ let (supervisor_port, supervisor_chan) = Chan::new();
let (mut infos, mut threads) = (~[], ~[]);
for i in range(0, thread_count) {
let (worker_port, worker_chan) = Chan::new();