Skip to content

Commit 0777ce8

Browse files
committed
rustdoc: Freeze the cache ASAP
The cache is going to be used earlier in the HTML generation process, which means that it needs to get into TLS as soon as possible.
1 parent 356423d commit 0777ce8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/librustdoc/html/render.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,17 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
307307
}
308308

309309
let index = try!(build_index(&krate, &mut cache));
310-
try!(write_shared(&cx, &krate, &cache, index));
310+
311+
// Freeze the cache now that the index has been built. Put an Arc into TLS
312+
// for future parallelization opportunities
313+
let cache = Arc::new(cache);
314+
cache_key.replace(Some(cache.clone()));
315+
316+
try!(write_shared(&cx, &krate, &*cache, index));
311317
let krate = try!(render_sources(&mut cx, krate));
312318

313319
// And finally render the whole crate's documentation
314-
cx.krate(krate, cache)
320+
cx.krate(krate)
315321
}
316322

317323
fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String> {
@@ -954,16 +960,13 @@ impl Context {
954960
///
955961
/// This currently isn't parallelized, but it'd be pretty easy to add
956962
/// parallelization to this function.
957-
fn krate(self, mut krate: clean::Crate, cache: Cache) -> io::IoResult<()> {
963+
fn krate(self, mut krate: clean::Crate) -> io::IoResult<()> {
958964
let mut item = match krate.module.take() {
959965
Some(i) => i,
960966
None => return Ok(())
961967
};
962968
item.name = Some(krate.name);
963969

964-
// using a rwarc makes this parallelizable in the future
965-
cache_key.replace(Some(Arc::new(cache)));
966-
967970
let mut work = vec!((self, item));
968971
loop {
969972
match work.pop() {

0 commit comments

Comments
 (0)