about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-08-12 12:53:45 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2019-08-26 19:15:19 -0400
commit3307929a849592d8ea36b10f92192e31867f76e3 (patch)
tree064fc5f2929478617dc78334f5185d534155f2ec
parent0e079c2c689b6252154e9df04d067783bfc13224 (diff)
downloadrust-3307929a849592d8ea36b10f92192e31867f76e3.tar.gz
rust-3307929a849592d8ea36b10f92192e31867f76e3.zip
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.
-rw-r--r--src/librustdoc/html/format.rs12
-rw-r--r--src/librustdoc/html/render.rs10
2 files changed, 11 insertions, 11 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 182a72b6a4d..54c0120e398 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -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,
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 896246126d8..67084991276 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -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() {