Store only the current depth
Previously we stored the entire current path which is a bit expensive and only ever accessed its length. This stores the length directly.
This commit is contained in:
parent
0e079c2c68
commit
3307929a84
2 changed files with 11 additions and 11 deletions
|
@ -15,7 +15,7 @@ use rustc::hir;
|
|||
|
||||
use crate::clean::{self, PrimitiveType};
|
||||
use crate::html::item_type::ItemType;
|
||||
use crate::html::render::{self, cache, CURRENT_LOCATION_KEY};
|
||||
use crate::html::render::{self, cache, CURRENT_DEPTH};
|
||||
|
||||
/// Helper to render an optional visibility with a space after it (if the
|
||||
/// visibility is preset)
|
||||
|
@ -407,16 +407,16 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
|
|||
return None
|
||||
}
|
||||
|
||||
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
||||
let depth = CURRENT_DEPTH.with(|l| l.get());
|
||||
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
|
||||
Some(&(ref fqp, shortty)) => {
|
||||
(fqp, shortty, "../".repeat(loc.len()))
|
||||
(fqp, shortty, "../".repeat(depth))
|
||||
}
|
||||
None => {
|
||||
let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
|
||||
(fqp, shortty, match cache.extern_locations[&did.krate] {
|
||||
(.., render::Remote(ref s)) => s.to_string(),
|
||||
(.., render::Local) => "../".repeat(loc.len()),
|
||||
(.., render::Local) => "../".repeat(depth),
|
||||
(.., render::Unknown) => return None,
|
||||
})
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ fn primitive_link(f: &mut fmt::Formatter<'_>,
|
|||
if !f.alternate() {
|
||||
match m.primitive_locations.get(&prim) {
|
||||
Some(&def_id) if def_id.is_local() => {
|
||||
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
||||
let len = CURRENT_DEPTH.with(|s| s.get());
|
||||
let len = if len == 0 {0} else {len - 1};
|
||||
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
|
||||
"../".repeat(len),
|
||||
|
@ -492,7 +492,7 @@ fn primitive_link(f: &mut fmt::Formatter<'_>,
|
|||
Some((cname, s.to_string()))
|
||||
}
|
||||
(ref cname, _, render::Local) => {
|
||||
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
||||
let len = CURRENT_DEPTH.with(|s| s.get());
|
||||
Some((cname, "../".repeat(len)))
|
||||
}
|
||||
(.., render::Unknown) => None,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
pub use self::ExternalLocation::*;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::default::Default;
|
||||
|
@ -479,7 +479,7 @@ impl ToJson for IndexItemFunctionType {
|
|||
}
|
||||
|
||||
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
|
||||
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> = RefCell::new(Vec::new()));
|
||||
thread_local!(pub static CURRENT_DEPTH: Cell<usize> = Cell::new(0));
|
||||
|
||||
pub fn initial_ids() -> Vec<String> {
|
||||
[
|
||||
|
@ -695,7 +695,7 @@ pub fn run(mut krate: clean::Crate,
|
|||
// for future parallelization opportunities
|
||||
let cache = Arc::new(cache);
|
||||
CACHE_KEY.with(|v| *v.borrow_mut() = cache.clone());
|
||||
CURRENT_LOCATION_KEY.with(|s| s.borrow_mut().clear());
|
||||
CURRENT_DEPTH.with(|s| s.set(0));
|
||||
|
||||
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
|
||||
Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
|
||||
|
@ -2003,8 +2003,8 @@ impl Context {
|
|||
-> io::Result<()> {
|
||||
// A little unfortunate that this is done like this, but it sure
|
||||
// does make formatting *a lot* nicer.
|
||||
CURRENT_LOCATION_KEY.with(|slot| {
|
||||
*slot.borrow_mut() = self.current.clone();
|
||||
CURRENT_DEPTH.with(|slot| {
|
||||
slot.set(self.current.len());
|
||||
});
|
||||
|
||||
let mut title = if it.is_primitive() || it.is_keyword() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue