Remove some users of io::file_reader
This commit is contained in:
parent
ff95904c48
commit
2290ce14f2
6 changed files with 68 additions and 30 deletions
|
|
@ -8,17 +8,21 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::io;
|
||||
|
||||
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
|
||||
|
||||
// Load any test directives embedded in the file
|
||||
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
||||
use std::rt::io::Open;
|
||||
use std::rt::io::file::FileInfo;
|
||||
use std::rt::io::buffered::BufferedReader;
|
||||
|
||||
let mut error_patterns = ~[];
|
||||
let rdr = io::file_reader(testfile).unwrap();
|
||||
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
|
||||
let mut line_num = 1u;
|
||||
while !rdr.eof() {
|
||||
let ln = rdr.read_line();
|
||||
loop {
|
||||
let ln = match rdr.read_line() {
|
||||
Some(ln) => ln, None => break,
|
||||
};
|
||||
error_patterns.push_all_move(parse_expected(line_num, ln));
|
||||
line_num += 1u;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ use common::config;
|
|||
use common;
|
||||
use util;
|
||||
|
||||
use std::io;
|
||||
|
||||
pub struct TestProps {
|
||||
// Lines that should be expected, in order, on standard out
|
||||
error_patterns: ~[~str],
|
||||
|
|
@ -104,17 +102,23 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
|
|||
!val
|
||||
}
|
||||
|
||||
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
|
||||
let rdr = io::file_reader(testfile).unwrap();
|
||||
while !rdr.eof() {
|
||||
let ln = rdr.read_line();
|
||||
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
|
||||
use std::rt::io::Open;
|
||||
use std::rt::io::file::FileInfo;
|
||||
use std::rt::io::buffered::BufferedReader;
|
||||
|
||||
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
|
||||
loop {
|
||||
let ln = match rdr.read_line() {
|
||||
Some(ln) => ln, None => break
|
||||
};
|
||||
|
||||
// Assume that any directives will be found before the first
|
||||
// module or function. This doesn't seem to be an optimization
|
||||
// with a warm page cache. Maybe with a cold one.
|
||||
if ln.starts_with("fn") || ln.starts_with("mod") {
|
||||
return true;
|
||||
} else { if !(it(ln)) { return false; } }
|
||||
} else { if !(it(ln.trim())) { return false; } }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,14 +89,14 @@ impl<R: Reader> BufferedReader<R> {
|
|||
/// Reads the next line of input, interpreted as a sequence of utf-8
|
||||
/// encoded unicode codepoints. If a newline is encountered, then the
|
||||
/// newline is contained in the returned string.
|
||||
pub fn read_line(&mut self) -> ~str {
|
||||
str::from_utf8_owned(self.read_until('\n' as u8))
|
||||
pub fn read_line(&mut self) -> Option<~str> {
|
||||
self.read_until('\n' as u8).map(str::from_utf8_owned)
|
||||
}
|
||||
|
||||
/// Reads a sequence of bytes leading up to a specified delimeter. Once the
|
||||
/// specified byte is encountered, reading ceases and the bytes up to and
|
||||
/// including the delimiter are returned.
|
||||
pub fn read_until(&mut self, byte: u8) -> ~[u8] {
|
||||
pub fn read_until(&mut self, byte: u8) -> Option<~[u8]> {
|
||||
let mut res = ~[];
|
||||
let mut used;
|
||||
loop {
|
||||
|
|
@ -120,7 +120,7 @@ impl<R: Reader> BufferedReader<R> {
|
|||
self.pos += used;
|
||||
}
|
||||
self.pos += used;
|
||||
return res;
|
||||
return if res.len() == 0 {None} else {Some(res)};
|
||||
}
|
||||
|
||||
fn fill_buffer<'a>(&'a mut self) -> &'a [u8] {
|
||||
|
|
|
|||
|
|
@ -462,6 +462,16 @@ pub trait Reader {
|
|||
fn eof(&mut self) -> bool;
|
||||
}
|
||||
|
||||
impl Reader for ~Reader {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.read(buf) }
|
||||
fn eof(&mut self) -> bool { self.eof() }
|
||||
}
|
||||
|
||||
impl<'self> Reader for &'self mut Reader {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.read(buf) }
|
||||
fn eof(&mut self) -> bool { self.eof() }
|
||||
}
|
||||
|
||||
pub trait Writer {
|
||||
/// Write the given buffer
|
||||
///
|
||||
|
|
@ -474,6 +484,16 @@ pub trait Writer {
|
|||
fn flush(&mut self);
|
||||
}
|
||||
|
||||
impl Writer for ~Writer {
|
||||
fn write(&mut self, buf: &[u8]) { self.write(buf) }
|
||||
fn flush(&mut self) { self.flush() }
|
||||
}
|
||||
|
||||
impl<'self> Writer for &'self mut Writer {
|
||||
fn write(&mut self, buf: &[u8]) { self.write(buf) }
|
||||
fn flush(&mut self) { self.flush() }
|
||||
}
|
||||
|
||||
pub trait Stream: Reader + Writer { }
|
||||
|
||||
impl<T: Reader + Writer> Stream for T {}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
extern mod extra;
|
||||
|
||||
use extra::time::precise_time_s;
|
||||
use std::io;
|
||||
use std::os;
|
||||
use std::rand::Rng;
|
||||
use std::rand;
|
||||
|
|
@ -70,11 +69,15 @@ fn shift_push() {
|
|||
}
|
||||
|
||||
fn read_line() {
|
||||
use std::rt::io::{Reader, Open};
|
||||
use std::rt::io::file::FileInfo;
|
||||
use std::rt::io::buffered::BufferedReader;
|
||||
|
||||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
|
||||
for _ in range(0, 3) {
|
||||
let reader = io::file_reader(&path).unwrap();
|
||||
let mut reader = BufferedReader::new(path.open_reader(Open).unwrap());
|
||||
while !reader.eof() {
|
||||
reader.read_line();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,17 +156,21 @@ fn make_sequence_processor(sz: uint,
|
|||
|
||||
// given a FASTA file on stdin, process sequence THREE
|
||||
fn main() {
|
||||
use std::rt::io::{Reader, Open};
|
||||
use std::rt::io::file::FileInfo;
|
||||
use std::rt::io::native::stdio;
|
||||
use std::rt::io::buffered::BufferedReader;
|
||||
|
||||
let rdr = if os::getenv("RUST_BENCH").is_some() {
|
||||
// FIXME: Using this compile-time env variable is a crummy way to
|
||||
// get to this massive data set, but include_bin! chokes on it (#2598)
|
||||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
io::file_reader(&path).unwrap()
|
||||
} else {
|
||||
io::stdin()
|
||||
};
|
||||
|
||||
|
||||
// FIXME: Using this compile-time env variable is a crummy way to
|
||||
// get to this massive data set, but include_bin! chokes on it (#2598)
|
||||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
~path.open_reader(Open).unwrap() as ~Reader
|
||||
} else {
|
||||
~stdio::stdin() as ~Reader
|
||||
};
|
||||
let mut rdr = BufferedReader::new(rdr);
|
||||
|
||||
// initialize each sequence sorter
|
||||
let sizes = ~[1u,2,3,4,6,12,18];
|
||||
|
|
@ -193,8 +197,11 @@ fn main() {
|
|||
// reading the sequence of interest
|
||||
let mut proc_mode = false;
|
||||
|
||||
while !rdr.eof() {
|
||||
let line: ~str = rdr.read_line();
|
||||
loop {
|
||||
let line = match rdr.read_line() {
|
||||
Some(ln) => ln, None => break,
|
||||
};
|
||||
let line = line.trim().to_owned();
|
||||
|
||||
if line.len() == 0u { continue; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue