diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs
index 5ffce95c383..84a4981fb3c 100644
--- a/src/libcore/dvec.rs
+++ b/src/libcore/dvec.rs
@@ -161,7 +161,6 @@ impl extensions for dvec {
vec::push(self.data, t);
}
-
#[doc = "Remove and return the first element"]
fn shift() -> A {
self.borrow { |v|
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index ff7bdb2b2d6..39322f68ad7 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -52,7 +52,7 @@ impl reader_util for reader {
i += 1u;
assert (w > 0u);
if w == 1u {
- chars += [ b0 as char ]/~;
+ vec::push(chars, b0 as char );
cont;
}
// can't satisfy this char with the existing data
@@ -71,7 +71,7 @@ impl reader_util for reader {
// See str::char_at
val += ((b0 << ((w + 1u) as u8)) as uint)
<< (w - 1u) * 6u - w - 1u;
- chars += [ val as char ]/~;
+ vec::push(chars, val as char );
}
ret (i, 0u);
}
@@ -86,7 +86,7 @@ impl reader_util for reader {
// we're split in a unicode char?
break;
}
- buf += data;
+ vec::push_all(buf, data);
let (offset, nbreq) = chars_from_buf(buf, chars);
let ncreq = n - vec::len(chars);
// again we either know we need a certain number of bytes
@@ -110,11 +110,11 @@ impl reader_util for reader {
}
fn read_line() -> str {
- let mut buf: [u8]/~ = []/~;
+ let mut buf = []/~;
loop {
let ch = self.read_byte();
if ch == -1 || ch == 10 { break; }
- buf += [ch as u8]/~;
+ vec::push(buf, ch as u8);
}
str::from_bytes(buf)
}
@@ -123,7 +123,7 @@ impl reader_util for reader {
let mut buf: [u8]/~ = []/~;
loop {
let ch = self.read_byte();
- if ch < 1 { break; } else { buf += [ch as u8]/~; }
+ if ch < 1 { break; } else { vec::push(buf, ch as u8); }
}
str::from_bytes(buf)
}
@@ -158,7 +158,7 @@ impl reader_util for reader {
fn read_whole_stream() -> [u8]/~ {
let mut buf: [u8]/~ = []/~;
- while !self.eof() { buf += self.read_bytes(2048u); }
+ while !self.eof() { vec::push_all(buf, self.read_bytes(2048u)); }
buf
}
@@ -453,7 +453,7 @@ fn u64_to_le_bytes(n: u64, size: uint, f: fn([u8]/&) -> T) -> T {
let mut bytes: [u8]/~ = []/~, i = size, n = n;
while i > 0u {
- bytes += [(n & 255_u64) as u8]/~;
+ vec::push(bytes, (n & 255_u64) as u8);
n >>= 8_u64;
i -= 1u;
}
@@ -485,7 +485,7 @@ fn u64_to_be_bytes(n: u64, size: uint, f: fn([u8]/&) -> T) -> T {
let mut i = size;
while i > 0u {
let shift = ((i - 1u) * 8u) as u64;
- bytes += [(n >> shift) as u8]/~;
+ vec::push(bytes, (n >> shift) as u8);
i -= 1u;
}
f(bytes)
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 63d833e197f..0367398c5d0 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -122,7 +122,7 @@ Convert a vector of bytes to a UTF-8 string
Fails if invalid UTF-8
"]
-pure fn from_bytes(vv: [u8]/~) -> str {
+pure fn from_bytes(+vv: [u8]/~) -> str {
assert is_utf8(vv);
ret unsafe { unsafe::from_bytes(vv) };
}
@@ -1750,9 +1750,9 @@ mod unsafe {
Does not verify that the vector contains valid UTF-8.
"]
- unsafe fn from_bytes(v: [const u8]/~) -> str {
+ unsafe fn from_bytes(+v: [const u8]/~) -> str {
unsafe {
- let mut vcopy = ::unsafe::transmute(copy v);
+ let mut vcopy = ::unsafe::transmute(v);
vec::push(vcopy, 0u8);
::unsafe::transmute(vcopy)
}
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 46ae0fdf34e..be402f317a1 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -384,13 +384,12 @@ fn shift(&v: [T]/~) -> T {
let mut rr;
{
let vv = unsafe::to_ptr(vv);
- let mut r <- *vv;
+ rr <- *vv;
for uint::range(1u, ln) {|i|
let r <- *ptr::offset(vv, i);
push(v, r);
}
- rr <- r;
}
unsafe::set_len(vv, 0u);
diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs
new file mode 100644
index 00000000000..823900ac55b
--- /dev/null
+++ b/src/test/bench/core-std.rs
@@ -0,0 +1,48 @@
+// Microbenchmarks for various functions in core and std
+
+use std;
+
+import std::time::precise_time_s;
+
+import io::{reader, reader_util};
+
+fn main() {
+ #macro[
+ [#bench[id],
+ run_test(#stringify(id), id)]
+ ];
+
+ #bench[shift_push];
+ #bench[read_line];
+}
+
+fn run_test(name: str, test: fn()) {
+ let start = precise_time_s();
+ test();
+ let stop = precise_time_s();
+
+ io::println(#fmt("%s:\t\t%f ms", name, (stop - start) * 1000f));
+}
+
+fn shift_push() {
+ let mut v1 = vec::from_elem(30000, 1);
+ let mut v2 = []/~;
+
+ while v1.len() > 0 {
+ vec::push(v2, vec::shift(v1));
+ }
+}
+
+fn read_line() {
+ let path = path::connect(
+ #env("CFG_SRC_DIR"),
+ "src/test/bench/shootout-k-nucleotide.data"
+ );
+
+ for int::range(0, 3) {|_i|
+ let reader = result::get(io::file_reader(path));
+ while !reader.eof() {
+ reader.read_line();
+ }
+ }
+}
diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs
index b6811db4b62..e83b660b9bb 100644
--- a/src/test/bench/shootout-k-nucleotide.rs
+++ b/src/test/bench/shootout-k-nucleotide.rs
@@ -62,29 +62,32 @@ fn find(mm: hashmap<[u8]/~, uint>, key: str) -> uint {
}
// given a map, increment the counter for a key
-fn update_freq(mm: hashmap<[u8]/~, uint>, key: [u8]/~) {
- alt mm.find(key) {
+fn update_freq(mm: hashmap<[u8]/~, uint>, key: [u8]/&) {
+ let key = vec::slice(key, 0, key.len());
+ alt mm.find(key) {
option::none { mm.insert(key, 1u ); }
option::some(val) { mm.insert(key, 1u + val); }
- }
+ }
}
// given a [u8]/~, for each window call a function
// i.e., for "hello" and windows of size four,
// run it("hell") and it("ello"), then return "llo"
-fn windows_with_carry(bb: [const u8]/~, nn: uint, it: fn(window: [u8]/~)) -> [u8]/~ {
+fn windows_with_carry(bb: [const u8]/~, nn: uint,
+ it: fn(window: [u8]/&)) -> [u8]/~ {
let mut ii = 0u;
let len = vec::len(bb);
while ii < len - (nn - 1u) {
- it(vec::slice(bb, ii, ii+nn));
+ it(vec::view(bb, ii, ii+nn));
ii += 1u;
}
ret vec::slice(bb, len - (nn - 1u), len);
}
-fn make_sequence_processor(sz: uint, from_parent: comm::port<[u8]/~>, to_parent: comm::chan) {
+fn make_sequence_processor(sz: uint, from_parent: comm::port<[u8]/~>,
+ to_parent: comm::chan) {
let freqs: hashmap<[u8]/~, uint> = map::bytes_hash();
let mut carry: [u8]/~ = []/~;