rustdoc: Use a BufferedWriter when emitting source

This takes the rendering time of source files for libstd from 12.5s to 0.1s,
turns out write! calls the write function *a lot*
This commit is contained in:
Alex Crichton 2013-09-30 16:08:12 -07:00
parent cc1791584f
commit fb259855dc
2 changed files with 13 additions and 3 deletions

View File

@ -28,6 +28,7 @@ use std::vec;
use extra::arc::RWArc;
use extra::json::ToJson;
use extra::sort;
use extra::time;
use syntax::ast;
use syntax::ast_util::is_local;
@ -179,6 +180,8 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
w.flush();
}
info2!("emitting source files");
let started = time::precise_time_ns();
{
let dst = cx.dst.push("src");
mkdir(&dst);
@ -191,9 +194,14 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
};
crate = folder.fold_crate(crate);
}
let ended = time::precise_time_ns();
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
// Now render the whole crate.
info2!("rendering the whole crate");
let started = time::precise_time_ns();
cx.crate(crate, cache);
let ended = time::precise_time_ns();
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
}
fn write(dst: Path, contents: &str) {
@ -289,7 +297,8 @@ impl<'self> SourceCollector<'self> {
}
let dst = cur.push(*p.components.last() + ".html");
let mut w = dst.open_writer(io::CreateOrTruncate);
let w = dst.open_writer(io::CreateOrTruncate);
let mut w = BufferedWriter::new(w);
let title = format!("{} -- source", *dst.components.last());
let page = layout::Page {
@ -299,6 +308,7 @@ impl<'self> SourceCollector<'self> {
};
layout::render(&mut w as &mut io::Writer, &self.cx.layout,
&page, &(""), &Source(contents.as_slice()));
w.flush();
return true;
}
}

View File

@ -146,7 +146,7 @@ pub fn main_args(args: &[~str]) -> int {
}
}
let ended = time::precise_time_ns();
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1000000000f64);
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
return 0;
}