auto merge of #2360 : Ms2ger/servo/vec, r=jdm

This commit is contained in:
bors-servo 2014-05-07 09:28:27 -04:00
commit 15d3257a29
7 changed files with 31 additions and 39 deletions

View file

@ -4290,7 +4290,6 @@ class CGBindingRoot(CGThing):
'script_task::JSPageInfo',
'libc',
'servo_util::str::DOMString',
'servo_util::vec::zip_copies',
'std::cast',
'std::cmp',
'std::ptr',

View file

@ -641,7 +641,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let win = window_from_node(self).root();
let node: &JSRef<Node> = NodeCast::from_ref(self);
let rects = node.get_content_boxes();
let rects: ~[Root<ClientRect>] = rects.iter().map(|r| {
let rects: Vec<Root<ClientRect>> = rects.iter().map(|r| {
ClientRect::new(
&*win,
r.origin.y,

View file

@ -6,7 +6,6 @@ use collections::HashMap;
use rand;
use rand::Rng;
use std::hash::{Hash, sip};
use std::slice;
use std::slice::Items;
#[cfg(test)]
@ -179,7 +178,7 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for LRUCache<K,V> {
}
pub struct SimpleHashCache<K,V> {
entries: ~[Option<(K,V)>],
entries: Vec<Option<(K,V)>>,
k0: u64,
k1: u64,
}
@ -188,7 +187,7 @@ impl<K:Clone+Eq+Hash,V:Clone> SimpleHashCache<K,V> {
pub fn new(cache_size: uint) -> SimpleHashCache<K,V> {
let mut r = rand::task_rng();
SimpleHashCache {
entries: slice::from_elem(cache_size, None),
entries: Vec::from_elem(cache_size, None),
k0: r.gen(),
k1: r.gen(),
}
@ -207,8 +206,8 @@ impl<K:Clone+Eq+Hash,V:Clone> SimpleHashCache<K,V> {
#[inline]
pub fn find_equiv<'a,Q:Hash+Equiv<K>>(&'a self, key: &Q) -> Option<&'a V> {
let bucket_index = self.bucket_for_key(key);
match self.entries[bucket_index] {
Some((ref existing_key, ref value)) if key.equiv(existing_key) => Some(value),
match self.entries.get(bucket_index) {
&Some((ref existing_key, ref value)) if key.equiv(existing_key) => Some(value),
_ => None,
}
}
@ -217,13 +216,13 @@ impl<K:Clone+Eq+Hash,V:Clone> SimpleHashCache<K,V> {
impl<K:Clone+Eq+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[bucket_index] = Some((key, value))
*self.entries.get_mut(bucket_index) = Some((key, value))
}
fn find(&mut self, key: &K) -> Option<V> {
let bucket_index = self.bucket_for_key(key);
match self.entries[bucket_index] {
Some((ref existing_key, ref value)) if existing_key == key => Some((*value).clone()),
match self.entries.get(bucket_index) {
&Some((ref existing_key, ref value)) if existing_key == key => Some((*value).clone()),
_ => None,
}
}

View file

@ -89,10 +89,10 @@ pub mod test {
let mut rng = rand::task_rng();
for _ in range(0, 50000) {
let len: uint = rng.gen();
let mut v: ~[int] = rng.gen_vec((len % 32) + 1).iter().map(|&x| x).collect();
sort::quicksort(v);
let mut v: Vec<int> = rng.gen_vec((len % 32) + 1).iter().map(|&x| x).collect();
sort::quicksort(v.as_mut_slice());
for i in range(0, v.len() - 1) {
assert!(v[i] <= v[i + 1])
assert!(v.get(i) <= v.get(i + 1))
}
}
}

View file

@ -67,12 +67,6 @@ fn test_match<T: Eq>(b: &T, a: Option<&T>) -> bool {
}
}
pub fn zip_copies<A: Clone, B: Clone>(avec: &[A], bvec: &[B]) -> ~[(A,B)] {
avec.iter().map(|x| x.clone())
.zip(bvec.iter().map(|x| x.clone()))
.collect()
}
#[test]
fn should_find_all_elements() {
let arr_odd = [1, 2, 4, 6, 7, 8, 9];

View file

@ -26,7 +26,7 @@ struct Config {
fn main() {
let args = os::args();
let config = parse_config(args);
let config = parse_config(args.move_iter().collect());
let opts = test_options(config.clone());
let tests = find_tests(config);
match run_tests_console(&opts, tests) {
@ -36,10 +36,10 @@ fn main() {
}
}
fn parse_config(args: ~[~str]) -> Config {
fn parse_config(args: Vec<~str>) -> Config {
let args = args.tail();
let opts = ~[reqopt("s", "source-dir", "source-dir", "source-dir")];
let matches = match getopts(args, opts) {
let opts = vec!(reqopt("s", "source-dir", "source-dir", "source-dir"));
let matches = match getopts(args, opts.as_slice()) {
Ok(m) => m,
Err(f) => fail!(f.to_err_msg())
};
@ -121,7 +121,7 @@ fn run_test(file: ~str) {
}
let out = str::from_utf8(output.as_slice());
let lines: ~[&str] = out.unwrap().split('\n').collect();
let lines: Vec<&str> = out.unwrap().split('\n').collect();
for &line in lines.iter() {
if line.contains("TEST-UNEXPECTED-FAIL") {
fail!(line.to_owned());

View file

@ -60,7 +60,7 @@ struct Reftest {
kind: ReftestKind,
files: [~str, ..2],
id: uint,
servo_args: ~[~str],
servo_args: Vec<~str>,
}
fn parse_lists(filenames: &[~str], servo_args: &[~str]) -> Vec<TestDescAndFn> {
@ -82,29 +82,29 @@ fn parse_lists(filenames: &[~str], servo_args: &[~str]) -> Vec<TestDescAndFn> {
continue;
}
let parts: ~[&str] = line.split(' ').filter(|p| !p.is_empty()).collect();
let parts: Vec<&str> = line.split(' ').filter(|p| !p.is_empty()).collect();
if parts.len() != 3 {
fail!("reftest line: '{:s}' doesn't match 'KIND LEFT RIGHT'", line);
}
let kind = match parts[0] {
"==" => Same,
"!=" => Different,
_ => fail!("reftest line: '{:s}' has invalid kind '{:s}'",
line, parts[0])
let kind = match parts.get(0) {
& &"==" => Same,
& &"!=" => Different,
&part => fail!("reftest line: '{:s}' has invalid kind '{:s}'",
line, part)
};
let src_path = file_path.dir_path();
let src_dir = src_path.display().to_str();
let file_left = src_dir + "/" + parts[1];
let file_right = src_dir + "/" + parts[2];
let file_left = src_dir + "/" + *parts.get(1);
let file_right = src_dir + "/" + *parts.get(2);
let reftest = Reftest {
name: parts[1] + " / " + parts[2],
name: parts.get(1) + " / " + *parts.get(2),
kind: kind,
files: [file_left, file_right],
id: next_id,
servo_args: servo_args.to_owned(),
servo_args: servo_args.iter().map(|x| x.clone()).collect(),
};
next_id += 1;
@ -132,9 +132,9 @@ fn make_test(reftest: Reftest) -> TestDescAndFn {
fn capture(reftest: &Reftest, side: uint) -> png::Image {
let filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side);
let mut args = reftest.servo_args.clone();
args.push_all_move(~["-f".to_owned(), "-o".to_owned(), filename.clone(), reftest.files[side].clone()]);
args.push_all_move(vec!("-f".to_owned(), "-o".to_owned(), filename.clone(), reftest.files[side].clone()));
let retval = match Process::status("./servo", args) {
let retval = match Process::status("./servo", args.as_slice()) {
Ok(status) => status,
Err(e) => fail!("failed to execute process: {}", e),
};
@ -147,7 +147,7 @@ fn check_reftest(reftest: Reftest) {
let left = capture(&reftest, 0);
let right = capture(&reftest, 1);
let pixels: ~[u8] = left.pixels.iter().zip(right.pixels.iter()).map(|(&a, &b)| {
let pixels: Vec<u8> = left.pixels.iter().zip(right.pixels.iter()).map(|(&a, &b)| {
if a as i8 - b as i8 == 0 {
// White for correct
0xFF
@ -168,7 +168,7 @@ fn check_reftest(reftest: Reftest) {
width: left.width,
height: left.height,
color_type: png::RGBA8,
pixels: pixels,
pixels: pixels.move_iter().collect(),
};
let res = png::store_png(&img, &output);
assert!(res.is_ok());