auto merge of #9749 : alexcrichton/rust/less-io, r=brson

This implements a number of the baby steps needed to start eliminating everything inside of `std::io`. It turns out that there are a *lot* of users of that module, so I'm going to try to tackle them separately instead of bringing down the whole system all at once.

This pull implements a large amount of unimplemented functionality inside of `std::rt::io` including:

* Native file I/O (file descriptors, *FILE)
* Native stdio (through the native file descriptors)
* Native processes (extracted from `std::run`)

I also found that there are a number of users of `std::io` which desire to read an input line-by-line, so I added an implementation of `read_until` and `read_line` to `BufferedReader`.

With all of these changes in place, I started to axe various usages of `std::io`. There's a lot of one-off uses here-and-there, but the major use-case remaining that doesn't have a fantastic solution is `extra::json`. I ran into a few compiler bugs when attempting to remove that, so I figured I'd come back to it later instead. 

There is one fairly major change in this pull, and it's moving from native stdio to uv stdio via `print` and `println`. Unfortunately logging still goes through native I/O (via `dumb_println`). This is going to need some thinking, because I still want the goal of logging/printing to be 0 allocations, and this is not possible if `io::stdio::stderr()` is called on each log message. Instead I think that this may need to be cached as the `logger` field inside the `Task` struct, but that will require a little more workings to get right (this is also a similar problem for print/println, do we cache `stdout()` to not have to re-create it every time?).
This commit is contained in:
bors 2013-10-10 04:31:24 -07:00
commit 0ede2ea4e2
21 changed files with 1385 additions and 1007 deletions

View file

@ -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();
}

View file

@ -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; }