aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/util
diff options
context:
space:
mode:
authorJack Moffitt <jack@metajack.im>2013-10-14 23:11:35 -0600
committerJack Moffitt <jack@metajack.im>2013-10-21 17:38:34 -0600
commit94202661c03500fffcc7ec3e566e2a2a168c7dfc (patch)
tree111764fc98e2cfe3995e2c9d20332c29b989f761 /src/components/util
parent8b47221ff8c77281eb55c5c671f23ae455cfe6bd (diff)
downloadservo-94202661c03500fffcc7ec3e566e2a2a168c7dfc.tar.gz
servo-94202661c03500fffcc7ec3e566e2a2a168c7dfc.zip
Update to latest Rust.
Diffstat (limited to 'src/components/util')
-rw-r--r--src/components/util/debug.rs2
-rw-r--r--src/components/util/geometry.rs62
-rw-r--r--src/components/util/range.rs4
-rw-r--r--src/components/util/time.rs18
-rw-r--r--src/components/util/url.rs16
-rw-r--r--src/components/util/util.rc2
-rw-r--r--src/components/util/vec.rs2
7 files changed, 57 insertions, 49 deletions
diff --git a/src/components/util/debug.rs b/src/components/util/debug.rs
index 1c4549fc27a..67a1d7d5f21 100644
--- a/src/components/util/debug.rs
+++ b/src/components/util/debug.rs
@@ -5,7 +5,7 @@
use std::io;
use std::vec::raw::buf_as_slice;
use std::cast::transmute;
-use std::sys::size_of;
+use std::mem::size_of;
fn hexdump_slice(buf: &[u8]) {
let stderr = io::stderr();
diff --git a/src/components/util/geometry.rs b/src/components/util/geometry.rs
index b89d0f29343..4acc8d8dd72 100644
--- a/src/components/util/geometry.rs
+++ b/src/components/util/geometry.rs
@@ -57,23 +57,19 @@ pub fn min(x: Au, y: Au) -> Au { if x < y { x } else { y } }
pub fn max(x: Au, y: Au) -> Au { if x > y { x } else { y } }
impl NumCast for Au {
- fn from<T:NumCast>(n: T) -> Au { Au(n.to_i32()) }
-
- fn to_u8(&self) -> u8 { (**self).to_u8() }
- fn to_u16(&self) -> u16 { (**self).to_u16() }
- fn to_u32(&self) -> u32 { (**self).to_u32() }
- fn to_u64(&self) -> u64 { (**self).to_u64() }
- fn to_uint(&self) -> uint { (**self).to_uint() }
+ fn from<T:ToPrimitive>(n: T) -> Option<Au> {
+ Some(Au(n.to_i32().unwrap()))
+ }
+}
- fn to_i8(&self) -> i8 { (**self).to_i8() }
- fn to_i16(&self) -> i16 { (**self).to_i16() }
- fn to_i32(&self) -> i32 { (**self).to_i32() }
- fn to_i64(&self) -> i64 { (**self).to_i64() }
- fn to_int(&self) -> int { (**self).to_int() }
+impl ToPrimitive for Au {
+ fn to_i64(&self) -> Option<i64> {
+ Some(**self as i64)
+ }
- fn to_f32(&self) -> f32 { (**self).to_f32() }
- fn to_f64(&self) -> f64 { (**self).to_f64() }
- fn to_float(&self) -> float { (**self).to_float() }
+ fn to_u64(&self) -> Option<u64> {
+ Some(**self as u64)
+ }
}
pub fn box<T:Clone + Ord + Add<T,T> + Sub<T,T>>(x: T, y: T, w: T, h: T) -> Rect<T> {
@@ -81,16 +77,16 @@ pub fn box<T:Clone + Ord + Add<T,T> + Sub<T,T>>(x: T, y: T, w: T, h: T) -> Rect<
}
impl Au {
- pub fn scale_by(self, factor: float) -> Au {
- Au(((*self as float) * factor).round() as i32)
+ pub fn scale_by(self, factor: f64) -> Au {
+ Au(((*self as f64) * factor).round() as i32)
}
pub fn from_px(px: int) -> Au {
- NumCast::from(px * 60)
+ NumCast::from(px * 60).unwrap()
}
pub fn to_nearest_px(&self) -> int {
- ((**self as float) / 60f).round() as int
+ ((**self as f64) / 60f64).round() as int
}
pub fn to_snapped(&self) -> Au {
@@ -108,12 +104,12 @@ impl Au {
Rect(Point2D(z, z), Size2D(z, z))
}
- pub fn from_pt(pt: float) -> Au {
+ pub fn from_pt(pt: f64) -> Au {
from_px(pt_to_px(pt) as int)
}
- pub fn from_frac_px(px: float) -> Au {
- Au((px * 60f) as i32)
+ pub fn from_frac_px(px: f64) -> Au {
+ Au((px * 60f64) as i32)
}
pub fn min(x: Au, y: Au) -> Au { if *x < *y { x } else { y } }
@@ -121,13 +117,13 @@ impl Au {
}
// assumes 72 points per inch, and 96 px per inch
-pub fn pt_to_px(pt: float) -> float {
- pt / 72f * 96f
+pub fn pt_to_px(pt: f64) -> f64 {
+ pt / 72f64 * 96f64
}
// assumes 72 points per inch, and 96 px per inch
-pub fn px_to_pt(px: float) -> float {
- px / 96f * 72f
+pub fn px_to_pt(px: f64) -> f64 {
+ px / 96f64 * 72f64
}
pub fn zero_rect() -> Rect<Au> {
@@ -143,23 +139,23 @@ pub fn zero_size() -> Size2D<Au> {
Size2D(Au(0), Au(0))
}
-pub fn from_frac_px(px: float) -> Au {
- Au((px * 60f) as i32)
+pub fn from_frac_px(px: f64) -> Au {
+ Au((px * 60f64) as i32)
}
pub fn from_px(px: int) -> Au {
- NumCast::from(px * 60)
+ NumCast::from(px * 60).unwrap()
}
pub fn to_px(au: Au) -> int {
(*au / 60) as int
}
-pub fn to_frac_px(au: Au) -> float {
- (*au as float) / 60f
+pub fn to_frac_px(au: Au) -> f64 {
+ (*au as f64) / 60f64
}
// assumes 72 points per inch, and 96 px per inch
-pub fn from_pt(pt: float) -> Au {
- from_px((pt / 72f * 96f) as int)
+pub fn from_pt(pt: f64) -> Au {
+ from_px((pt / 72f64 * 96f64) as int)
}
diff --git a/src/components/util/range.rs b/src/components/util/range.rs
index 6f3ce3e9e86..a0943728a77 100644
--- a/src/components/util/range.rs
+++ b/src/components/util/range.rs
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::cmp::{max, min};
-use std::iterator;
+use std::iter;
enum RangeRelation {
OverlapsBegin(/* overlap */ uint),
@@ -36,7 +36,7 @@ impl Range {
pub fn length(&self) -> uint { self.len }
pub fn end(&self) -> uint { self.off + self.len }
- pub fn eachi(&self) -> iterator::Range<uint> {
+ pub fn eachi(&self) -> iter::Range<uint> {
range(self.off, self.off + self.len)
}
diff --git a/src/components/util/time.rs b/src/components/util/time.rs
index 58985410c54..35186ef3fa5 100644
--- a/src/components/util/time.rs
+++ b/src/components/util/time.rs
@@ -4,7 +4,7 @@
// Timing functions.
use std::comm::{Port, SharedChan};
-use std::iterator::AdditiveIterator;
+use std::iter::AdditiveIterator;
use std::rt::io::timer::Timer;
use std::task::spawn_with;
@@ -23,7 +23,7 @@ impl ProfilerChan {
pub enum ProfilerMsg {
// Normal message used for reporting time
- TimeMsg(ProfilerCategory, float),
+ TimeMsg(ProfilerCategory, f64),
// Message used to force print the profiling metrics
PrintMsg,
}
@@ -85,7 +85,7 @@ impl ProfilerCategory {
}
}
-type ProfilerBuckets = TreeMap<ProfilerCategory, ~[float]>;
+type ProfilerBuckets = TreeMap<ProfilerCategory, ~[f64]>;
// back end of the profiler that handles data aggregation and performance metrics
pub struct Profiler {
@@ -95,10 +95,10 @@ pub struct Profiler {
}
impl Profiler {
- pub fn create(port: Port<ProfilerMsg>, chan: ProfilerChan, period: Option<float>) {
+ pub fn create(port: Port<ProfilerMsg>, chan: ProfilerChan, period: Option<f64>) {
match period {
Some(period) => {
- let period = (period * 1000f) as u64;
+ let period = (period * 1000f64) as u64;
do spawn {
let mut timer = Timer::new().unwrap();
loop {
@@ -164,7 +164,7 @@ impl Profiler {
let data_len = data.len();
if data_len > 0 {
let (mean, median, &min, &max) =
- (data.iter().map(|&x|x).sum() / (data_len as float),
+ (data.iter().map(|&x|x).sum() / (data_len as f64),
data[data_len / 2],
data.iter().min().unwrap(),
data.iter().max().unwrap());
@@ -184,7 +184,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 float / 1000000f);
+ let ms = ((end_time - start_time) as f64 / 1000000f64);
profiler_chan.send(TimeMsg(category, ms));
return val;
}
@@ -193,8 +193,8 @@ pub fn time<T>(msg: &str, callback: &fn() -> T) -> T{
let start_time = precise_time_ns();
let val = callback();
let end_time = precise_time_ns();
- let ms = ((end_time - start_time) as float / 1000000f);
- if ms >= 5f {
+ let ms = ((end_time - start_time) as f64 / 1000000f64);
+ if ms >= 5f64 {
debug!("%s took %? ms", msg, ms);
}
return val;
diff --git a/src/components/util/url.rs b/src/components/util/url.rs
index a2a3b07d537..309117081ec 100644
--- a/src/components/util/url.rs
+++ b/src/components/util/url.rs
@@ -27,7 +27,10 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
if str_url.starts_with("/") {
~"file://" + str_url
} else {
- ~"file://" + os::getcwd().push(str_url).to_str()
+ let mut path = os::getcwd();
+ path.push(str_url);
+ // FIXME (#1094): not the right way to transform a path
+ ~"file://" + path.display().to_str()
}
} else {
let current_url = current_url.unwrap();
@@ -57,7 +60,12 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
match scheme {
~"about" => {
match page {
- ~"failure" => ~"file://" + os::getcwd().push("../src/test/html/failure.html").to_str(),
+ ~"failure" => {
+ let mut path = os::getcwd();
+ path.push("../src/test/html/failure.html");
+ // FIXME (#1094): not the right way to transform a path
+ ~"file://" + path.display().to_str()
+ }
// TODO: handle the rest of the about: pages
_ => str_url
}
@@ -88,7 +96,9 @@ mod make_url_tests {
let url = make_url(file, None);
debug!("url: %?", url);
assert!(url.scheme == ~"file");
- assert!(url.path.contains(os::getcwd().to_str()));
+ let path = os::getcwd();
+ // FIXME (#1094): not the right way to transform a path
+ assert!(url.path.contains(path.display().to_str()));
}
#[test]
diff --git a/src/components/util/util.rc b/src/components/util/util.rc
index 946ffb21f4a..bbcf7203740 100644
--- a/src/components/util/util.rc
+++ b/src/components/util/util.rc
@@ -8,6 +8,8 @@
url = "http://servo.org/")];
#[crate_type = "lib"];
+#[feature(macro_rules)];
+
extern mod extra;
extern mod geom;
diff --git a/src/components/util/vec.rs b/src/components/util/vec.rs
index 93c900192de..76ddb5cd978 100644
--- a/src/components/util/vec.rs
+++ b/src/components/util/vec.rs
@@ -11,7 +11,7 @@ pub trait BinarySearchMethods<'self, T: Ord + Eq> {
impl<'self, T: Ord + Eq> BinarySearchMethods<'self, T> for &'self [T] {
fn binary_search(&self, key: &T) -> Option<&'self T> {
- self.binary_search_index(key).map(|i| &self[*i])
+ self.binary_search_index(key).map(|i| &self[i])
}
fn binary_search_index(&self, key: &T) -> Option<uint> {