Skip to content

Compile speed #8802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ Some examples of call expressions:
# fn add(x: int, y: int) -> int { 0 }

let x: int = add(1, 2);
let pi = FromStr::from_str::<f32>("3.14");
let pi: Option<f32> = FromStr::from_str("3.14");
~~~~

### Lambda expressions
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/crypto/cryptoutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ mod test {
#[test]
#[should_fail]
fn test_add_bytes_to_bits_tuple_overflow2() {
add_bytes_to_bits_tuple::<u64>((Bounded::max_value::<u64>() - 1, 0), 0x8000000000000000);
let value: u64 = Bounded::max_value();
add_bytes_to_bits_tuple::<u64>((value - 1, 0), 0x8000000000000000);
}
}
18 changes: 9 additions & 9 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ mod tests {

#[test]
fn test_basic() {
let mut m = DList::new::<~int>();
let mut m: DList<~int> = DList::new();
assert_eq!(m.pop_front(), None);
assert_eq!(m.pop_back(), None);
assert_eq!(m.pop_front(), None);
Expand Down Expand Up @@ -768,7 +768,7 @@ mod tests {

#[test]
fn test_rotate() {
let mut n = DList::new::<int>();
let mut n: DList<int> = DList::new();
n.rotate_backward(); check_links(&n);
assert_eq!(n.len(), 0);
n.rotate_forward(); check_links(&n);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ mod tests {

#[cfg(test)]
fn fuzz_test(sz: int) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
let mut v = ~[];
for i in range(0, sz) {
check_links(&m);
Expand Down Expand Up @@ -1078,23 +1078,23 @@ mod tests {

#[bench]
fn bench_push_front(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_front(0);
}
}

#[bench]
fn bench_push_back(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_back(0);
}
}

#[bench]
fn bench_push_back_pop_back(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_back(0);
m.pop_back();
Expand All @@ -1103,7 +1103,7 @@ mod tests {

#[bench]
fn bench_push_front_pop_front(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_front(0);
m.pop_front();
Expand All @@ -1112,7 +1112,7 @@ mod tests {

#[bench]
fn bench_rotate_forward(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
m.push_front(0);
m.push_front(1);
do b.iter {
Expand All @@ -1122,7 +1122,7 @@ mod tests {

#[bench]
fn bench_rotate_backward(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
m.push_front(0);
m.push_front(1);
do b.iter {
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub mod rustrt {

#[link_name = "rustrt"]
extern {
pub fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;

pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
Expand Down
76 changes: 50 additions & 26 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl Integer for BigUint {

fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
let mut m = a;
let mut d = Zero::zero::<BigUint>();
let mut d: BigUint = Zero::zero();
let mut n = 1;
while m >= b {
let (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
Expand Down Expand Up @@ -411,8 +411,9 @@ impl Integer for BigUint {
if shift == 0 {
return (BigUint::new(d), One::one(), (*b).clone());
}
let one: BigUint = One::one();
return (BigUint::from_slice(d).shl_unit(shift),
One::one::<BigUint>().shl_unit(shift),
one.shl_unit(shift),
b.shl_unit(shift));
}
}
Expand Down Expand Up @@ -1168,8 +1169,8 @@ mod biguint_tests {
#[test]
fn test_shl() {
fn check(s: &str, shift: uint, ans: &str) {
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() << shift)
.to_str_radix(16);
let opt_biguint: Option<BigUint> = FromStrRadix::from_str_radix(s, 16);
let bu = (opt_biguint.unwrap() << shift).to_str_radix(16);
assert_eq!(bu.as_slice(), ans);
}

Expand Down Expand Up @@ -1206,8 +1207,9 @@ mod biguint_tests {
#[test]
fn test_shr() {
fn check(s: &str, shift: uint, ans: &str) {
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() >> shift)
.to_str_radix(16);
let opt_biguint: Option<BigUint> =
FromStrRadix::from_str_radix(s, 16);
let bu = (opt_biguint.unwrap() >> shift).to_str_radix(16);
assert_eq!(bu.as_slice(), ans);
}

Expand Down Expand Up @@ -1445,11 +1447,18 @@ mod biguint_tests {

#[test]
fn test_is_even() {
assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd());
assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd());
let one: Option<BigUint> = FromStr::from_str("1");
let two: Option<BigUint> = FromStr::from_str("2");
let thousand: Option<BigUint> = FromStr::from_str("1000");
let big: Option<BigUint> =
FromStr::from_str("1000000000000000000000");
let bigger: Option<BigUint> =
FromStr::from_str("1000000000000000000001");
assert!(one.unwrap().is_odd());
assert!(two.unwrap().is_even());
assert!(thousand.unwrap().is_even());
assert!(big.unwrap().is_even());
assert!(bigger.unwrap().is_odd());
assert!((BigUint::from_uint(1) << 64).is_even());
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
}
Expand Down Expand Up @@ -1534,15 +1543,19 @@ mod biguint_tests {
}
}

assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None);
let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10);
assert_eq!(zed, None);
let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2);
assert_eq!(blank, None);
let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1",
10);
assert_eq!(minus_one, None);
}

#[test]
fn test_factor() {
fn factor(n: uint) -> BigUint {
let mut f= One::one::<BigUint>();
let mut f: BigUint = One::one();
for i in range(2, n + 1) {
// FIXME(#6102): Assignment operator for BigInt causes ICE
// f *= BigUint::from_uint(i);
Expand Down Expand Up @@ -1939,17 +1952,24 @@ mod bigint_tests {

#[test]
fn test_abs_sub() {
assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero());
assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero());
assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one());
assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()),
IntConvertible::from_int(2));
let zero: BigInt = Zero::zero();
let one: BigInt = One::one();
assert_eq!((-one).abs_sub(&one), zero);
let one: BigInt = One::one();
let zero: BigInt = Zero::zero();
assert_eq!(one.abs_sub(&one), zero);
let one: BigInt = One::one();
let zero: BigInt = Zero::zero();
assert_eq!(one.abs_sub(&zero), one);
let one: BigInt = One::one();
assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2));
}

#[test]
fn test_to_str_radix() {
fn check(n: int, ans: &str) {
assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));
let n: BigInt = IntConvertible::from_int(n);
assert!(ans == n.to_str_radix(10));
}
check(10, "10");
check(1, "1");
Expand All @@ -1962,7 +1982,10 @@ mod bigint_tests {
#[test]
fn test_from_str_radix() {
fn check(s: &str, ans: Option<int>) {
let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
let ans = ans.map_move(|n| {
let x: BigInt = IntConvertible::from_int(n);
x
});
assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
}
check("10", Some(10));
Expand All @@ -1980,7 +2003,8 @@ mod bigint_tests {
BigInt::new(Minus, ~[1, 1, 1]));
assert!(-BigInt::new(Minus, ~[1, 1, 1]) ==
BigInt::new(Plus, ~[1, 1, 1]));
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
let zero: BigInt = Zero::zero();
assert_eq!(-zero, zero);
}
}

Expand All @@ -1992,16 +2016,16 @@ mod bench {
use extra::test::BenchHarness;

fn factorial(n: uint) -> BigUint {
let mut f = One::one::<BigUint>();
let mut f: BigUint = One::one();
for i in iterator::range_inclusive(1, n) {
f = f * BigUint::from_uint(i);
}
f
}

fn fib(n: uint) -> BigUint {
let mut f0 = Zero::zero::<BigUint>();
let mut f1 = One::one::<BigUint>();
let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one();
for _ in range(0, n) {
let f2 = f0 + f1;
f0 = util::replace(&mut f1, f2);
Expand Down
29 changes: 20 additions & 9 deletions src/libextra/num/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,13 @@ impl<T: FromStr + Clone + Integer + Ord>
/// Parses `numer/denom`.
fn from_str(s: &str) -> Option<Ratio<T>> {
let split: ~[&str] = s.splitn_iter('/', 1).collect();
if split.len() < 2 { return None; }
do FromStr::from_str::<T>(split[0]).chain |a| {
do FromStr::from_str::<T>(split[1]).chain |b| {
if split.len() < 2 {
return None
}
let a_option: Option<T> = FromStr::from_str(split[0]);
do a_option.chain |a| {
let b_option: Option<T> = FromStr::from_str(split[1]);
do b_option.chain |b| {
Some(Ratio::new(a.clone(), b.clone()))
}
}
Expand All @@ -282,10 +286,15 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
let split: ~[&str] = s.splitn_iter('/', 1).collect();
if split.len() < 2 { None }
else {
do FromStrRadix::from_str_radix::<T>(split[0], radix).chain |a| {
do FromStrRadix::from_str_radix::<T>(split[1], radix).chain |b| {
if split.len() < 2 {
None
} else {
let a_option: Option<T> = FromStrRadix::from_str_radix(split[0],
radix);
do a_option.chain |a| {
let b_option: Option<T> =
FromStrRadix::from_str_radix(split[1], radix);
do b_option.chain |b| {
Some(Ratio::new(a.clone(), b.clone()))
}
}
Expand Down Expand Up @@ -496,7 +505,8 @@ mod test {
#[test]
fn test_from_str_fail() {
fn test(s: &str) {
assert_eq!(FromStr::from_str::<Rational>(s), None);
let rational: Option<Rational> = FromStr::from_str(s);
assert_eq!(rational, None);
}

let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1"];
Expand Down Expand Up @@ -536,7 +546,8 @@ mod test {
#[test]
fn test_from_str_radix_fail() {
fn test(s: &str) {
assert_eq!(FromStrRadix::from_str_radix::<Rational>(s, 3), None);
let radix: Option<Rational> = FromStrRadix::from_str_radix(s, 3);
assert_eq!(radix, None);
}

let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"];
Expand Down
19 changes: 14 additions & 5 deletions src/libextra/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,27 +338,36 @@ mod tests {

#[test]
#[should_fail]
fn test_empty_pop() { let mut heap = PriorityQueue::new::<int>(); heap.pop(); }
fn test_empty_pop() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
heap.pop();
}

#[test]
fn test_empty_maybe_pop() {
let mut heap = PriorityQueue::new::<int>();
let mut heap: PriorityQueue<int> = PriorityQueue::new();
assert!(heap.maybe_pop().is_none());
}

#[test]
#[should_fail]
fn test_empty_top() { let empty = PriorityQueue::new::<int>(); empty.top(); }
fn test_empty_top() {
let empty: PriorityQueue<int> = PriorityQueue::new();
empty.top();
}

#[test]
fn test_empty_maybe_top() {
let empty = PriorityQueue::new::<int>();
let empty: PriorityQueue<int> = PriorityQueue::new();
assert!(empty.maybe_top().is_none());
}

#[test]
#[should_fail]
fn test_empty_replace() { let mut heap = PriorityQueue::new(); heap.replace(5); }
fn test_empty_replace() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
heap.replace(5);
}

#[test]
fn test_from_iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ mod tests {
#[bench]
fn bench_new(b: &mut test::BenchHarness) {
do b.iter {
let _ = RingBuf::new::<u64>();
let _: RingBuf<u64> = RingBuf::new();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub fn write_boxplot(w: @io::Writer, s: &Summary, width_hint: uint) {
/// Returns a HashMap with the number of occurrences of every element in the
/// sequence that the iterator exposes.
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
let mut map = hashmap::HashMap::new::<U, uint>();
let mut map: hashmap::HashMap<U,uint> = hashmap::HashMap::new();
for elem in iter {
map.insert_or_update_with(elem, 1, |_, count| *count += 1);
}
Expand Down
Loading