diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 013433336a1..20d4c417655 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -10,7 +10,6 @@ //! Support for inlining external documentation into the current AST. -use std::collections::HashSet; use std::iter::once; use syntax::ast; @@ -21,6 +20,7 @@ use rustc::hir::def::Def; use rustc::hir::def_id::DefId; use rustc::hir::print as pprust; use rustc::ty::{self, TyCtxt}; +use rustc::util::nodemap::FnvHashSet; use rustc_const_eval::lookup_const_by_id; @@ -425,7 +425,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext, .into_iter() .map(|meth| meth.name.to_string()) .collect() - }).unwrap_or(HashSet::new()); + }).unwrap_or(FnvHashSet()); ret.push(clean::Item { inner: clean::ImplItem(clean::Impl { @@ -461,7 +461,7 @@ fn build_module<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>, // If we're reexporting a reexport it may actually reexport something in // two namespaces, so the target may be listed twice. Make sure we only // visit each node at most once. - let mut visited = HashSet::new(); + let mut visited = FnvHashSet(); for item in tcx.sess.cstore.item_children(did) { match item.def { cstore::DlDef(Def::ForeignMod(did)) => { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c8620254b6f..cd425b7c9eb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -43,10 +43,10 @@ use rustc::hir::print as pprust; use rustc::ty::subst::Substs; use rustc::ty; use rustc::middle::stability; +use rustc::util::nodemap::{FnvHashMap, FnvHashSet}; use rustc::hir; -use std::collections::{HashMap, HashSet}; use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; @@ -121,7 +121,7 @@ pub struct Crate { pub access_levels: Arc>, // These are later on moved into `CACHEKEY`, leaving the map empty. // Only here so that they can be filtered through the rustdoc passes. - pub external_traits: HashMap, + pub external_traits: FnvHashMap, } struct CrateNum(ast::CrateNum); @@ -1010,7 +1010,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics<'tcx>, // Note that associated types also have a sized bound by default, but we // don't actually know the set of associated types right here so that's // handled in cleaning associated types - let mut sized_params = HashSet::new(); + let mut sized_params = FnvHashSet(); where_predicates.retain(|pred| { match *pred { WP::BoundPredicate { ty: Generic(ref g), ref bounds } => { @@ -1656,9 +1656,9 @@ impl From for PrimitiveType { struct SubstAlias<'a, 'tcx: 'a> { tcx: &'a ty::TyCtxt<'a, 'tcx, 'tcx>, // Table type parameter definition -> substituted type - ty_substs: HashMap, + ty_substs: FnvHashMap, // Table node id of lifetime parameter definition -> substituted lifetime - lt_substs: HashMap, + lt_substs: FnvHashMap, } impl<'a, 'tcx: 'a, 'b: 'tcx> Folder for SubstAlias<'a, 'tcx> { @@ -1727,8 +1727,8 @@ impl Clean for hir::Ty { let item = tcx.map.expect_item(node_id); if let hir::ItemTy(ref ty, ref generics) = item.node { let provided_params = &path.segments.last().unwrap().parameters; - let mut ty_substs = HashMap::new(); - let mut lt_substs = HashMap::new(); + let mut ty_substs = FnvHashMap(); + let mut lt_substs = FnvHashMap(); for (i, ty_param) in generics.ty_params.iter().enumerate() { let ty_param_def = tcx.expect_def(ty_param.id); if let Some(ty) = provided_params.types().get(i).cloned() @@ -2384,7 +2384,7 @@ impl Clean for hir::ImplPolarity { pub struct Impl { pub unsafety: hir::Unsafety, pub generics: Generics, - pub provided_trait_methods: HashSet, + pub provided_trait_methods: FnvHashSet, pub trait_: Option, pub for_: Type, pub items: Vec, @@ -2410,7 +2410,7 @@ impl Clean> for doctree::Impl { .map(|meth| meth.name.to_string()) .collect() }) - }).unwrap_or(HashSet::new()); + }).unwrap_or(FnvHashSet()); ret.push(Item { name: None, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8032b5c3104..26f792a1fdf 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -18,6 +18,7 @@ use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, TyCtxt}; use rustc::hir::map as hir_map; use rustc::lint; +use rustc::util::nodemap::{FnvHashMap, FnvHashSet}; use rustc_trans::back::link; use rustc_resolve as resolve; use rustc_metadata::cstore::CStore; @@ -28,7 +29,6 @@ use errors; use errors::emitter::ColorConfig; use std::cell::{RefCell, Cell}; -use std::collections::{HashMap, HashSet}; use std::rc::Rc; use visit_ast::RustdocVisitor; @@ -45,13 +45,13 @@ pub enum MaybeTyped<'a, 'tcx: 'a> { NotTyped(&'a session::Session) } -pub type ExternalPaths = HashMap, clean::TypeKind)>; +pub type ExternalPaths = FnvHashMap, clean::TypeKind)>; pub struct DocContext<'a, 'tcx: 'a> { pub map: &'a hir_map::Map<'tcx>, pub maybe_typed: MaybeTyped<'a, 'tcx>, pub input: Input, - pub populated_crate_impls: RefCell>, + pub populated_crate_impls: RefCell>, pub deref_trait_did: Cell>, // Note that external items for which `doc(hidden)` applies to are shown as // non-reachable while local items aren't. This is because we're reusing @@ -61,7 +61,7 @@ pub struct DocContext<'a, 'tcx: 'a> { /// Later on moved into `html::render::CACHE_KEY` pub renderinfo: RefCell, /// Later on moved through `clean::Crate` into `html::render::CACHE_KEY` - pub external_traits: RefCell>, + pub external_traits: RefCell>, } impl<'b, 'tcx> DocContext<'b, 'tcx> { @@ -178,10 +178,10 @@ pub fn run_core(search_paths: SearchPaths, map: &tcx.map, maybe_typed: Typed(tcx), input: input, - populated_crate_impls: RefCell::new(HashSet::new()), + populated_crate_impls: RefCell::new(FnvHashSet()), deref_trait_did: Cell::new(None), access_levels: RefCell::new(access_levels), - external_traits: RefCell::new(HashMap::new()), + external_traits: RefCell::new(FnvHashMap()), renderinfo: RefCell::new(Default::default()), }; debug!("crate: {:?}", ctxt.map.krate()); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6993f85c3d9..5cb5cc05187 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -37,7 +37,7 @@ pub use self::ExternalLocation::*; use std::ascii::AsciiExt; use std::cell::RefCell; use std::cmp::Ordering; -use std::collections::{BTreeMap, HashMap, HashSet}; +use std::collections::BTreeMap; use std::default::Default; use std::error; use std::fmt::{self, Display, Formatter}; @@ -61,6 +61,7 @@ use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; use rustc::session::config::get_unstable_features_setting; use rustc::hir; +use rustc::util::nodemap::{FnvHashMap, FnvHashSet}; use clean::{self, Attributes, GetDefId}; use doctree; @@ -114,9 +115,9 @@ pub struct SharedContext { /// `true`. pub include_sources: bool, /// The local file sources we've emitted and their respective url-paths. - pub local_sources: HashMap, + pub local_sources: FnvHashMap, /// All the passes that were run on this crate. - pub passes: HashSet, + pub passes: FnvHashSet, /// The base-URL of the issue tracker for when an item has been tagged with /// an issue number. pub issue_tracker_base_url: Option, @@ -211,7 +212,7 @@ pub struct Cache { /// Mapping of typaram ids to the name of the type parameter. This is used /// when pretty-printing a type (so pretty printing doesn't have to /// painfully maintain a context like this) - pub typarams: HashMap, + pub typarams: FnvHashMap, /// Maps a type id to all known implementations for that type. This is only /// recognized for intra-crate `ResolvedPath` types, and is used to print @@ -219,35 +220,35 @@ pub struct Cache { /// /// The values of the map are a list of implementations and documentation /// found on that implementation. - pub impls: HashMap>, + pub impls: FnvHashMap>, /// Maintains a mapping of local crate node ids to the fully qualified name /// and "short type description" of that node. This is used when generating /// URLs when a type is being linked to. External paths are not located in /// this map because the `External` type itself has all the information /// necessary. - pub paths: HashMap, ItemType)>, + pub paths: FnvHashMap, ItemType)>, /// Similar to `paths`, but only holds external paths. This is only used for /// generating explicit hyperlinks to other crates. - pub external_paths: HashMap, ItemType)>, + pub external_paths: FnvHashMap, ItemType)>, /// This map contains information about all known traits of this crate. /// Implementations of a crate should inherit the documentation of the /// parent trait if no extra documentation is specified, and default methods /// should show up in documentation about trait implementations. - pub traits: HashMap, + pub traits: FnvHashMap, /// When rendering traits, it's often useful to be able to list all /// implementors of the trait, and this mapping is exactly, that: a mapping /// of trait ids to the list of known implementors of the trait - pub implementors: HashMap>, + pub implementors: FnvHashMap>, /// Cache of where external crate documentation can be found. - pub extern_locations: HashMap, + pub extern_locations: FnvHashMap, /// Cache of where documentation for primitives can be found. - pub primitive_locations: HashMap, + pub primitive_locations: FnvHashMap, // Note that external items for which `doc(hidden)` applies to are shown as // non-reachable while local items aren't. This is because we're reusing @@ -260,7 +261,7 @@ pub struct Cache { parent_stack: Vec, parent_is_trait_impl: bool, search_index: Vec, - seen_modules: HashSet, + seen_modules: FnvHashSet, seen_mod: bool, stripped_mod: bool, deref_trait_did: Option, @@ -277,9 +278,9 @@ pub struct Cache { /// Later on moved into `CACHE_KEY`. #[derive(Default)] pub struct RenderInfo { - pub inlined: HashSet, + pub inlined: FnvHashSet, pub external_paths: ::core::ExternalPaths, - pub external_typarams: HashMap, + pub external_typarams: FnvHashMap, pub deref_trait_did: Option, } @@ -377,10 +378,10 @@ impl ToJson for IndexItemFunctionType { thread_local!(static CACHE_KEY: RefCell> = Default::default()); thread_local!(pub static CURRENT_LOCATION_KEY: RefCell> = RefCell::new(Vec::new())); -thread_local!(static USED_ID_MAP: RefCell> = +thread_local!(static USED_ID_MAP: RefCell> = RefCell::new(init_ids())); -fn init_ids() -> HashMap { +fn init_ids() -> FnvHashMap { [ "main", "search", @@ -407,7 +408,7 @@ pub fn reset_ids(embedded: bool) { *s.borrow_mut() = if embedded { init_ids() } else { - HashMap::new() + FnvHashMap() }; }); } @@ -432,7 +433,7 @@ pub fn derive_id(candidate: String) -> String { pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: PathBuf, - passes: HashSet, + passes: FnvHashSet, css_file_extension: Option, renderinfo: RenderInfo) -> Result<(), Error> { let src_root = match krate.src.parent() { @@ -443,7 +444,7 @@ pub fn run(mut krate: clean::Crate, src_root: src_root, passes: passes, include_sources: true, - local_sources: HashMap::new(), + local_sources: FnvHashMap(), issue_tracker_base_url: None, layout: layout::Layout { logo: "".to_string(), @@ -513,22 +514,22 @@ pub fn run(mut krate: clean::Crate, .collect(); let mut cache = Cache { - impls: HashMap::new(), + impls: FnvHashMap(), external_paths: external_paths, - paths: HashMap::new(), - implementors: HashMap::new(), + paths: FnvHashMap(), + implementors: FnvHashMap(), stack: Vec::new(), parent_stack: Vec::new(), search_index: Vec::new(), parent_is_trait_impl: false, - extern_locations: HashMap::new(), - primitive_locations: HashMap::new(), - seen_modules: HashSet::new(), + extern_locations: FnvHashMap(), + primitive_locations: FnvHashMap(), + seen_modules: FnvHashSet(), seen_mod: false, stripped_mod: false, access_levels: krate.access_levels.clone(), orphan_methods: Vec::new(), - traits: mem::replace(&mut krate.external_traits, HashMap::new()), + traits: mem::replace(&mut krate.external_traits, FnvHashMap()), deref_trait_did: deref_trait_did, typarams: external_typarams, }; @@ -574,7 +575,7 @@ pub fn run(mut krate: clean::Crate, /// Build the search index from the collected metadata fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { - let mut nodeid_to_pathid = HashMap::new(); + let mut nodeid_to_pathid = FnvHashMap(); let mut crate_items = Vec::with_capacity(cache.search_index.len()); let mut crate_paths = Vec::::new(); @@ -2515,7 +2516,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, #[derive(Copy, Clone)] enum AssocItemLink<'a> { Anchor(Option<&'a str>), - GotoSource(DefId, &'a HashSet), + GotoSource(DefId, &'a FnvHashSet), } impl<'a> AssocItemLink<'a> { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 7d1dbbe5dc0..e7edf8d1cab 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -9,7 +9,6 @@ // except according to those terms. use std::cell::{RefCell, Cell}; -use std::collections::{HashMap, HashSet}; use std::env; use std::ffi::OsString; use std::io::prelude::*; @@ -29,6 +28,7 @@ use rustc::session::{self, config}; use rustc::session::config::{get_unstable_features_setting, OutputType, OutputTypes, Externs}; use rustc::session::search_paths::{SearchPaths, PathKind}; +use rustc::util::nodemap::{FnvHashMap, FnvHashSet}; use rustc_back::dynamic_lib::DynamicLibrary; use rustc_back::tempdir::TempDir; use rustc_driver::{driver, Compilation}; @@ -107,8 +107,8 @@ pub fn run(input: &str, map: &map, maybe_typed: core::NotTyped(&sess), input: input, - external_traits: RefCell::new(HashMap::new()), - populated_crate_impls: RefCell::new(HashSet::new()), + external_traits: RefCell::new(FnvHashMap()), + populated_crate_impls: RefCell::new(FnvHashSet()), deref_trait_did: Cell::new(None), access_levels: Default::default(), renderinfo: Default::default(), diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 0334c5ef5c4..f6084180f0b 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -11,7 +11,6 @@ //! Rust AST Visitor. Extracts useful information and massages it into a form //! usable for clean -use std::collections::HashSet; use std::mem; use syntax::abi; @@ -23,6 +22,7 @@ use syntax_pos::Span; use rustc::hir::map as hir_map; use rustc::hir::def::Def; use rustc::middle::privacy::AccessLevel; +use rustc::util::nodemap::FnvHashSet; use rustc::hir; @@ -42,14 +42,14 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> { pub module: Module, pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx>, - view_item_stack: HashSet, + view_item_stack: FnvHashSet, inlining_from_glob: bool, } impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { pub fn new(cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> { // If the root is reexported, terminate all recursion. - let mut stack = HashSet::new(); + let mut stack = FnvHashSet(); stack.insert(ast::CRATE_NODE_ID); RustdocVisitor { module: Module::new(None),