Skip to content

Commit 9ab85ac

Browse files
committed
---
yaml --- r: 63628 b: refs/heads/snap-stage3 c: c6515ee h: refs/heads/master v: v3
1 parent b779641 commit 9ab85ac

File tree

7 files changed

+63
-124
lines changed

7 files changed

+63
-124
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6291702cf334f4b1fe41662bc3b0d996ca7ced19
4+
refs/heads/snap-stage3: c6515ee6a7f424679e2b53336974a991dd3b71c8
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/arena.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -39,7 +39,7 @@ use core::prelude::*;
3939
use list::{MutList, MutCons, MutNil};
4040

4141
use core::at_vec;
42-
use core::cast::{transmute, transmute_mut_region};
42+
use core::cast::{transmute, transmute_mut, transmute_mut_region};
4343
use core::cast;
4444
use core::libc::size_t;
4545
use core::ptr;
@@ -74,6 +74,7 @@ struct Chunk {
7474
is_pod: bool,
7575
}
7676

77+
#[mutable]
7778
pub struct Arena {
7879
// The head is separated out from the list as a unbenchmarked
7980
// microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
269270

270271
// The external interface
271272
#[inline]
272-
pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
273+
pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
273274
unsafe {
274275
// XXX: Borrow check
275-
let this = transmute_mut_region(self);
276-
if !intrinsics::needs_drop::<T>() {
277-
return this.alloc_pod(op);
276+
let this = transmute_mut(self);
277+
if intrinsics::needs_drop::<T>() {
278+
this.alloc_nonpod(op)
279+
} else {
280+
this.alloc_pod(op)
278281
}
279-
// XXX: Borrow check
280-
let this = transmute_mut_region(self);
281-
this.alloc_nonpod(op)
282282
}
283283
}
284284
}
285285

286286
#[test]
287287
fn test_arena_destructors() {
288-
let mut arena = Arena();
288+
let arena = Arena();
289289
for uint::range(0, 10) |i| {
290290
// Arena allocate something with drop glue to make sure it
291291
// doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
300300
#[should_fail]
301301
#[ignore(cfg(windows))]
302302
fn test_arena_destructors_fail() {
303-
let mut arena = Arena();
303+
let arena = Arena();
304304
// Put some stuff in the arena.
305305
for uint::range(0, 10) |i| {
306306
// Arena allocate something with drop glue to make sure it

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,6 @@ pub trait IteratorUtil<A> {
226226
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
227227
-> ScanIterator<'r, A, B, Self, St>;
228228

229-
/// Creates an iterator that maps each element to an iterator,
230-
/// and yields the elements of the produced iterators
231-
///
232-
/// # Example
233-
///
234-
/// ~~~ {.rust}
235-
/// let xs = [2u, 3];
236-
/// let ys = [0u, 1, 0, 1, 2];
237-
/// let mut it = xs.iter().flat_map_(|&x| Counter::new(0u, 1).take_(x));
238-
/// // Check that `it` has the same elements as `ys`
239-
/// let mut i = 0;
240-
/// for it.advance |x: uint| {
241-
/// assert_eq!(x, ys[i]);
242-
/// i += 1;
243-
/// }
244-
/// ~~~
245-
// FIXME: #5898: should be called `flat_map`
246-
fn flat_map_<'r, B, U: Iterator<B>>(self, f: &'r fn(A) -> U)
247-
-> FlatMapIterator<'r, A, B, Self, U>;
248-
249229
/// An adaptation of an external iterator to the for-loop protocol of rust.
250230
///
251231
/// # Example
@@ -417,12 +397,6 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
417397
ScanIterator{iter: self, f: f, state: initial_state}
418398
}
419399

420-
#[inline]
421-
fn flat_map_<'r, B, U: Iterator<B>>(self, f: &'r fn(A) -> U)
422-
-> FlatMapIterator<'r, A, B, T, U> {
423-
FlatMapIterator{iter: self, f: f, subiter: None }
424-
}
425-
426400
/// A shim implementing the `for` loop iteration protocol for iterator objects
427401
#[inline]
428402
fn advance(&mut self, f: &fn(A) -> bool) -> bool {
@@ -899,34 +873,6 @@ impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B,
899873
}
900874
}
901875

902-
/// An iterator that maps each element to an iterator,
903-
/// and yields the elements of the produced iterators
904-
///
905-
// FIXME #6967: Dummy B parameter to get around type inference bug
906-
pub struct FlatMapIterator<'self, A, B, T, U> {
907-
priv iter: T,
908-
priv f: &'self fn(A) -> U,
909-
priv subiter: Option<U>,
910-
}
911-
912-
impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for
913-
FlatMapIterator<'self, A, B, T, U> {
914-
#[inline]
915-
fn next(&mut self) -> Option<B> {
916-
loop {
917-
for self.subiter.mut_iter().advance |inner| {
918-
for inner.advance |x| {
919-
return Some(x)
920-
}
921-
}
922-
match self.iter.next().map_consume(self.f) {
923-
None => return None,
924-
next => self.subiter = next,
925-
}
926-
}
927-
}
928-
}
929-
930876
/// An iterator which just modifies the contained state throughout iteration.
931877
pub struct UnfoldrIterator<'self, A, St> {
932878
priv f: &'self fn(&mut St) -> Option<A>,
@@ -1105,19 +1051,6 @@ mod tests {
11051051
assert_eq!(i, ys.len());
11061052
}
11071053

1108-
#[test]
1109-
fn test_iterator_flat_map() {
1110-
let xs = [0u, 3, 6];
1111-
let ys = [0u, 1, 2, 3, 4, 5, 6, 7, 8];
1112-
let mut it = xs.iter().flat_map_(|&x| Counter::new(x, 1).take_(3));
1113-
let mut i = 0;
1114-
for it.advance |x: uint| {
1115-
assert_eq!(x, ys[i]);
1116-
i += 1;
1117-
}
1118-
assert_eq!(i, ys.len());
1119-
}
1120-
11211054
#[test]
11221055
fn test_unfoldr() {
11231056
fn count(st: &mut uint) -> Option<uint> {
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// xfail-test
2-
3-
// Broken due to arena API problems.
4-
5-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
62
// file at the top-level directory of this distribution and at
73
// http://rust-lang.org/COPYRIGHT.
84
//
@@ -15,33 +11,35 @@
1511
extern mod extra;
1612
use extra::arena;
1713

18-
enum tree<'self> {
19-
nil,
20-
node(&'self tree<'self>, &'self tree<'self>, int),
14+
enum Tree<'self> {
15+
Nil,
16+
Node(&'self Tree<'self>, &'self Tree<'self>, int),
2117
}
2218

23-
fn item_check(t: &tree) -> int {
19+
fn item_check(t: &Tree) -> int {
2420
match *t {
25-
nil => { return 0; }
26-
node(left, right, item) => {
21+
Nil => { return 0; }
22+
Node(left, right, item) => {
2723
return item + item_check(left) - item_check(right);
2824
}
2925
}
3026
}
3127

32-
fn bottom_up_tree<'r>(arena: &'r mut arena::Arena, item: int, depth: int)
33-
-> &'r tree<'r> {
28+
fn bottom_up_tree<'r>(arena: &'r arena::Arena, item: int, depth: int)
29+
-> &'r Tree<'r> {
3430
if depth > 0 {
3531
return arena.alloc(
36-
|| node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
32+
|| Node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
3733
bottom_up_tree(arena, 2 * item, depth - 1),
3834
item));
3935
}
40-
return arena.alloc(|| nil);
36+
return arena.alloc(|| Nil);
4137
}
4238

4339
fn main() {
44-
let args = os::args();
40+
use std::os;
41+
use std::int;
42+
let args = std::os::args();
4543
let args = if os::getenv(~"RUST_BENCH").is_some() {
4644
~[~"", ~"17"]
4745
} else if args.len() <= 1u {
@@ -59,34 +57,34 @@ fn main() {
5957
max_depth = n;
6058
}
6159

62-
let mut stretch_arena = arena::Arena();
60+
let stretch_arena = arena::Arena();
6361
let stretch_depth = max_depth + 1;
64-
let stretch_tree = bottom_up_tree(&mut stretch_arena, 0, stretch_depth);
62+
let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
6563

66-
io::println(fmt!("stretch tree of depth %d\t check: %d",
64+
println(fmt!("stretch tree of depth %d\t check: %d",
6765
stretch_depth,
6866
item_check(stretch_tree)));
6967

70-
let mut long_lived_arena = arena::Arena();
71-
let long_lived_tree = bottom_up_tree(&mut long_lived_arena, 0, max_depth);
68+
let long_lived_arena = arena::Arena();
69+
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
7270
let mut depth = min_depth;
7371
while depth <= max_depth {
7472
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
7573
let mut chk = 0;
7674
let mut i = 1;
7775
while i <= iterations {
78-
let mut temp_tree = bottom_up_tree(&mut long_lived_arena, i, depth);
76+
let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
7977
chk += item_check(temp_tree);
80-
temp_tree = bottom_up_tree(&mut long_lived_arena, -i, depth);
78+
temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
8179
chk += item_check(temp_tree);
8280
i += 1;
8381
}
84-
io::println(fmt!("%d\t trees of depth %d\t check: %d",
82+
println(fmt!("%d\t trees of depth %d\t check: %d",
8583
iterations * 2, depth,
8684
chk));
8785
depth += 2;
8886
}
89-
io::println(fmt!("long lived trees of depth %d\t check: %d",
87+
println(fmt!("long lived tree of depth %d\t check: %d",
9088
max_depth,
9189
item_check(long_lived_tree)));
9290
}

branches/snap-stage3/src/test/bench/shootout-chameneos-redux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn show_number(nn: uint) -> ~str {
8585
out = show_digit(dig) + " " + out;
8686
}
8787

88-
return out;
88+
return ~" " + out;
8989
}
9090
9191
fn transform(aa: color, bb: color) -> color {

branches/snap-stage3/src/test/bench/shootout-fasta.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -19,16 +19,14 @@ extern mod extra;
1919

2020
use std::int;
2121
use std::io;
22-
use std::option;
2322
use std::os;
2423
use std::rand::Rng;
2524
use std::rand;
2625
use std::result;
2726
use std::str;
2827
use std::uint;
29-
use std::vec;
3028

31-
fn LINE_LENGTH() -> uint { return 60u; }
29+
static LINE_LENGTH: uint = 60u;
3230

3331
struct MyRandom {
3432
last: u32
@@ -81,7 +79,7 @@ fn make_random_fasta(wr: @io::Writer,
8179
for uint::range(0u, n as uint) |_i| {
8280
op.push_char(select_random(myrandom_next(rng, 100u32),
8381
copy genelist));
84-
if op.len() >= LINE_LENGTH() {
82+
if op.len() >= LINE_LENGTH {
8583
wr.write_line(op);
8684
op = ~"";
8785
}
@@ -90,18 +88,18 @@ fn make_random_fasta(wr: @io::Writer,
9088
}
9189

9290
fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
93-
unsafe {
94-
wr.write_line(~">" + id + " " + desc);
95-
let mut op: ~str = ~"";
96-
let sl: uint = s.len();
97-
for uint::range(0u, n as uint) |i| {
98-
str::raw::push_byte(&mut op, s[i % sl]);
99-
if op.len() >= LINE_LENGTH() {
100-
wr.write_line(op);
101-
op = ~"";
102-
}
91+
wr.write_line(~">" + id + " " + desc);
92+
let mut op = str::with_capacity( LINE_LENGTH );
93+
let sl = s.len();
94+
for uint::range(0u, n as uint) |i| {
95+
if (op.len() >= LINE_LENGTH) {
96+
wr.write_line( op );
97+
op = str::with_capacity( LINE_LENGTH );
10398
}
104-
if op.len() > 0u { wr.write_line(op); }
99+
op.push_char( s[i % sl] as char );
100+
}
101+
if op.len() > 0 {
102+
wr.write_line(op)
105103
}
106104
}
107105
@@ -111,7 +109,7 @@ fn acid(ch: char, prob: u32) -> AminoAcids {
111109
112110
fn main() {
113111
let args = os::args();
114-
let args = if os::getenv(~"RUST_BENCH").is_some() {
112+
let args = if os::getenv("RUST_BENCH").is_some() {
115113
// alioth tests k-nucleotide with this data at 25,000,000
116114
~[~"", ~"5000000"]
117115
} else if args.len() <= 1u {
@@ -120,9 +118,9 @@ fn main() {
120118
args
121119
};
122120

123-
let writer = if os::getenv(~"RUST_BENCH").is_some() {
121+
let writer = if os::getenv("RUST_BENCH").is_some() {
124122
result::get(&io::file_writer(&Path("./shootout-fasta.data"),
125-
~[io::Truncate, io::Create]))
123+
[io::Truncate, io::Create]))
126124
} else {
127125
io::stdout()
128126
};

branches/snap-stage3/src/test/bench/shootout-spectralnorm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use std::f64;
212
use std::from_str::FromStr;
313
use std::os;

0 commit comments

Comments
 (0)