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,42 +2065,50 @@ 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);
let mut buf = Vec::new(); info!("Recursing into {}", self.dst.display());
this.render_item(&mut buf, &item, false).unwrap();
// buf will be empty if the module is stripped and there is no redirect for it
if !buf.is_empty() {
this.shared.ensure_dir(&this.dst)?;
let joint_dst = this.dst.join("index.html");
scx.fs.write(&joint_dst, buf)?;
}
let m = match item.inner { let mut buf = Vec::new();
clean::StrippedItem(box clean::ModuleItem(m)) | self.render_item(&mut buf, &item, false).unwrap();
clean::ModuleItem(m) => m, // buf will be empty if the module is stripped and there is no redirect for it
_ => unreachable!() if !buf.is_empty() {
}; self.shared.ensure_dir(&self.dst)?;
let joint_dst = self.dst.join("index.html");
scx.fs.write(&joint_dst, buf)?;
}
// Render sidebar-items.js used throughout this module. let m = match item.inner {
if !this.render_redirect_pages { clean::StrippedItem(box clean::ModuleItem(m)) |
let items = this.build_sidebar_items(&m); clean::ModuleItem(m) => m,
let js_dst = this.dst.join("sidebar-items.js"); _ => unreachable!()
let mut v = Vec::new(); };
try_err!(write!(&mut v, "initSidebarItems({});",
as_json(&items)), &js_dst);
scx.fs.write(&js_dst, &v)?;
}
for item in m.items { // Render sidebar-items.js used throughout this module.
f(this, item); if !self.render_redirect_pages {
} let items = self.build_sidebar_items(&m);
let js_dst = self.dst.join("sidebar-items.js");
let mut v = Vec::new();
try_err!(write!(&mut v, "initSidebarItems({});",
as_json(&items)), &js_dst);
scx.fs.write(&js_dst, &v)?;
}
Ok(()) for item in m.items {
})?; f(self, item);
}
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();