1
Fork 0

Calculate span info on-demand instead of ahead of time

This should *vastly* reduce memory usage.
This commit is contained in:
Joshua Nelson 2020-12-11 23:01:26 -05:00
parent af6aa9f431
commit 4fa95b3a07
7 changed files with 69 additions and 69 deletions

View file

@ -103,7 +103,6 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
/// rustdoc tree).
#[derive(Clone)]
crate struct Context {
crate sess: Lrc<Session>,
/// Current hierarchy of components leading down to what's currently being
/// rendered
crate current: Vec<String>,
@ -124,6 +123,7 @@ crate struct Context {
}
crate struct SharedContext {
crate sess: Lrc<Session>,
/// The path to the crate root source minus the file name.
/// Used for simplifying paths to the highlighted source code files.
crate src_root: PathBuf,
@ -176,6 +176,10 @@ impl Context {
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext,);
self.dst.join(&filename)
}
fn sess(&self) -> &Session {
&self.shared.sess
}
}
impl SharedContext {
@ -459,6 +463,7 @@ impl FormatRenderer for Context {
}
let (sender, receiver) = channel();
let mut scx = SharedContext {
sess,
collapsed: krate.collapsed,
src_root,
include_sources,
@ -498,7 +503,6 @@ impl FormatRenderer for Context {
let cache = Arc::new(cache);
let mut cx = Context {
sess,
current: Vec::new(),
dst,
render_redirect_pages: false,
@ -1636,24 +1640,24 @@ impl Context {
/// of their crate documentation isn't known.
fn src_href(&self, item: &clean::Item, cache: &Cache) -> Option<String> {
let mut root = self.root_path();
let mut path = String::new();
let cnum = item.source.cnum(self.sess());
// We can safely ignore synthetic `SourceFile`s.
let file = match item.source.filename {
let file = match item.source.filename(self.sess()) {
FileName::Real(ref path) => path.local_path().to_path_buf(),
_ => return None,
};
let file = &file;
let (krate, path) = if item.source.cnum == LOCAL_CRATE {
let (krate, path) = if cnum == LOCAL_CRATE {
if let Some(path) = self.shared.local_sources.get(file) {
(&self.shared.layout.krate, path)
} else {
return None;
}
} else {
let (krate, src_root) = match *cache.extern_locations.get(&item.source.cnum)? {
let (krate, src_root) = match *cache.extern_locations.get(&cnum)? {
(ref name, ref src, ExternalLocation::Local) => (name, src),
(ref name, ref src, ExternalLocation::Remote(ref s)) => {
root = s.to_string();
@ -1672,11 +1676,10 @@ impl Context {
(krate, &path)
};
let lines = if item.source.loline == item.source.hiline {
item.source.loline.to_string()
} else {
format!("{}-{}", item.source.loline, item.source.hiline)
};
let loline = item.source.lo(self.sess()).line;
let hiline = item.source.hi(self.sess()).line;
let lines =
if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) };
Some(format!(
"{root}src/{krate}/{path}#{lines}",
root = Escape(&root),