Skip to content

Commit 66fd3c9

Browse files
committed
Fixed shootout-fasta.rs output
1 parent de64ff2 commit 66fd3c9

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/test/bench/shootout-fasta.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use std::str;
2828
use std::uint;
2929
use std::vec;
3030

31-
fn LINE_LENGTH() -> uint { return 60u; }
31+
static LINE_LENGTH: uint = 60u;
32+
33+
//fn LINE_LENGTH() -> uint { return 60u; }
3234

3335
struct MyRandom {
3436
last: u32
@@ -81,7 +83,7 @@ fn make_random_fasta(wr: @io::Writer,
8183
for uint::range(0u, n as uint) |_i| {
8284
op.push_char(select_random(myrandom_next(rng, 100u32),
8385
copy genelist));
84-
if op.len() >= LINE_LENGTH() {
86+
if op.len() >= LINE_LENGTH {
8587
wr.write_line(op);
8688
op = ~"";
8789
}
@@ -90,18 +92,20 @@ fn make_random_fasta(wr: @io::Writer,
9092
}
9193

9294
fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
95+
wr.write_line(~">" + id + " " + desc);
96+
let mut op = str::with_capacity( LINE_LENGTH );
97+
let sl = s.len();
9398
unsafe {
94-
wr.write_line(~">" + id + " " + desc);
95-
let mut op: ~str = ~"";
96-
let sl: uint = s.len();
9799
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 = ~"";
100+
if (op.len() >= LINE_LENGTH) {
101+
wr.write_line( op );
102+
op = str::with_capacity( LINE_LENGTH );
102103
}
104+
op.push_char( s[i % sl] as char );
105+
}
106+
if op.len() > 0 {
107+
wr.write_line(op)
103108
}
104-
if op.len() > 0u { wr.write_line(op); }
105109
}
106110
}
107111

0 commit comments

Comments
 (0)