Skip to content

Commit d1e62d6

Browse files
cache primitives before running clean over all crates items
1 parent 3a92b99 commit d1e62d6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/librustdoc/clean/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
2828
use rustc_span::{self, Pos};
2929
use rustc_typeck::hir_ty_to_ty;
3030

31+
use std::cell::RefCell;
3132
use std::collections::hash_map::Entry;
3233
use std::default::Default;
3334
use std::hash::Hash;
3435
use std::rc::Rc;
36+
use std::sync::Arc;
3537
use std::{mem, vec};
3638

3739
use crate::core::{self, DocContext, ImplTraitParam};
@@ -48,6 +50,13 @@ pub use self::types::Type::*;
4850
pub use self::types::Visibility::{Inherited, Public};
4951
pub use self::types::*;
5052

53+
thread_local!(static PRIMITIVES: RefCell<Arc<FxHashMap<PrimitiveType, DefId>>> =
54+
Default::default());
55+
56+
crate fn primitives() -> Arc<FxHashMap<PrimitiveType, DefId>> {
57+
PRIMITIVES.with(|c| c.borrow().clone())
58+
}
59+
5160
const FN_OUTPUT_NAME: &str = "Output";
5261

5362
pub trait Clean<T> {
@@ -126,7 +135,7 @@ impl Clean<ExternalCrate> for CrateNum {
126135
}
127136
None
128137
};
129-
let primitives = if root.is_local() {
138+
let primitives: Vec<(DefId, PrimitiveType, Attributes)> = if root.is_local() {
130139
cx.tcx
131140
.hir()
132141
.krate()
@@ -161,6 +170,13 @@ impl Clean<ExternalCrate> for CrateNum {
161170
.filter_map(as_primitive)
162171
.collect()
163172
};
173+
PRIMITIVES.with(|v| {
174+
let mut tmp = v.borrow_mut();
175+
let stored_primitives = Arc::make_mut(&mut *tmp);
176+
for (prim, did) in primitives.iter().map(|x| (x.1, x.0)) {
177+
stored_primitives.insert(prim, did);
178+
}
179+
});
164180

165181
let as_keyword = |res: Res| {
166182
if let Res::Def(DefKind::Mod, def_id) = res {

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ impl GetDefId for Type {
11731173
fn def_id(&self) -> Option<DefId> {
11741174
match *self {
11751175
ResolvedPath { did, .. } => Some(did),
1176-
Primitive(p) => cache().primitive_locations.get(&p).cloned(),
1176+
Primitive(p) => super::primitives().get(&p).cloned(),
11771177
BorrowedRef { type_: box Generic(..), .. } => {
11781178
Primitive(PrimitiveType::Reference).def_id()
11791179
}

0 commit comments

Comments
 (0)