1
Fork 0

Inline recurse into only callsite

This commit is contained in:
Mark Rousskov 2019-08-12 16:43:26 -04:00
parent edfd5556f1
commit b3f01753b0

View file

@ -1885,31 +1885,6 @@ impl Context {
"../".repeat(self.current.len()) "../".repeat(self.current.len())
} }
/// Recurse in the directory structure and change the "root path" to make
/// sure it always points to the top (relatively).
fn recurse<T, F>(&mut self, s: String, f: F) -> T where
F: FnOnce(&mut Context) -> T,
{
if s.is_empty() {
panic!("Unexpected empty destination: {:?}", self.current);
}
let prev = self.dst.clone();
self.dst.push(&s);
self.current.push(s);
info!("Recursing into {}", self.dst.display());
let ret = f(self);
info!("Recursed; leaving {}", self.dst.display());
// Go back to where we were at
self.dst = prev;
self.current.pop().unwrap();
ret
}
/// Main method for rendering a crate. /// Main method for rendering a crate.
/// ///
/// This currently isn't parallelized, but it'd be pretty easy to add /// This currently isn't parallelized, but it'd be pretty easy to add
@ -2090,17 +2065,22 @@ impl Context {
// modules are special because they add a namespace. We also need to // modules are special because they add a namespace. We also need to
// recurse into the items of the module as well. // recurse into the items of the module as well.
let name = item.name.as_ref().unwrap().to_string(); let name = item.name.as_ref().unwrap().to_string();
let mut item = Some(item); let scx = &self.shared;
let scx = self.shared.clone(); if name.is_empty() {
self.recurse(name, |this| { panic!("Unexpected empty destination: {:?}", self.current);
let item = item.take().unwrap(); }
let prev = self.dst.clone();
self.dst.push(&name);
self.current.push(name);
info!("Recursing into {}", self.dst.display());
let mut buf = Vec::new(); let mut buf = Vec::new();
this.render_item(&mut buf, &item, false).unwrap(); self.render_item(&mut buf, &item, false).unwrap();
// buf will be empty if the module is stripped and there is no redirect for it // buf will be empty if the module is stripped and there is no redirect for it
if !buf.is_empty() { if !buf.is_empty() {
this.shared.ensure_dir(&this.dst)?; self.shared.ensure_dir(&self.dst)?;
let joint_dst = this.dst.join("index.html"); let joint_dst = self.dst.join("index.html");
scx.fs.write(&joint_dst, buf)?; scx.fs.write(&joint_dst, buf)?;
} }
@ -2111,9 +2091,9 @@ impl Context {
}; };
// Render sidebar-items.js used throughout this module. // Render sidebar-items.js used throughout this module.
if !this.render_redirect_pages { if !self.render_redirect_pages {
let items = this.build_sidebar_items(&m); let items = self.build_sidebar_items(&m);
let js_dst = this.dst.join("sidebar-items.js"); let js_dst = self.dst.join("sidebar-items.js");
let mut v = Vec::new(); let mut v = Vec::new();
try_err!(write!(&mut v, "initSidebarItems({});", try_err!(write!(&mut v, "initSidebarItems({});",
as_json(&items)), &js_dst); as_json(&items)), &js_dst);
@ -2121,11 +2101,14 @@ impl Context {
} }
for item in m.items { for item in m.items {
f(this, item); f(self, item);
} }
Ok(()) info!("Recursed; leaving {}", self.dst.display());
})?;
// Go back to where we were at
self.dst = prev;
self.current.pop().unwrap();
} else if item.name.is_some() { } else if item.name.is_some() {
let mut buf = Vec::new(); let mut buf = Vec::new();
self.render_item(&mut buf, &item, true).unwrap(); self.render_item(&mut buf, &item, true).unwrap();