Skip to content

Commit d1fa49b

Browse files
committed
feat(rustdoc-json-types): introduce rustc-hash feature
This allows the public `rustdoc-types` crate to expose this feature easily and allows consumers of the crate to get the performance advantages from doing so. The reasoning for this was discussed on [Zulip][1] Changes: - Make `rustc-hash` optional but default to including it - Rename all occurrences of `FxHashMap` to `HashMap`. - Feature gate the import and rename the imported `FxHashMap` to `HashMap` - Introduce a type alias `FxHashMap` which resolves to the currently used `HashMap` (`rustc_hash::FxHashMap` or `std::collections::HashMap`) for use in `src/librustdoc`. [1]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types
1 parent c926476 commit d1fa49b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/rustdoc-json-types/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ edition = "2021"
66
[lib]
77
path = "lib.rs"
88

9+
[features]
10+
default = ["rustc-hash"]
11+
912
[dependencies]
1013
serde = { version = "1.0", features = ["derive"] }
11-
rustc-hash = "1.1.0"
14+
rustc-hash = { version = "1.1.0", optional = true }
1215

1316
[dev-dependencies]
1417
serde_json = "1.0"

src/rustdoc-json-types/lib.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
44
//! struct is the root of the JSON blob and all other items are contained within.
55
6+
#[cfg(not(feature = "rustc-hash"))]
7+
use std::collections::HashMap;
68
use std::path::PathBuf;
79

8-
pub use rustc_hash::FxHashMap;
10+
#[cfg(feature = "rustc-hash")]
11+
use rustc_hash::FxHashMap as HashMap;
912
use serde::{Deserialize, Serialize};
1013

14+
pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
15+
1116
/// The version of JSON output that this crate represents.
1217
///
1318
/// This integer is incremented with every breaking change to the API,
@@ -30,11 +35,11 @@ pub struct Crate {
3035
pub includes_private: bool,
3136
/// A collection of all items in the local crate as well as some external traits and their
3237
/// items that are referenced locally.
33-
pub index: FxHashMap<Id, Item>,
38+
pub index: HashMap<Id, Item>,
3439
/// Maps IDs to fully qualified paths and other info helpful for generating links.
35-
pub paths: FxHashMap<Id, ItemSummary>,
40+
pub paths: HashMap<Id, ItemSummary>,
3641
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
37-
pub external_crates: FxHashMap<u32, ExternalCrate>,
42+
pub external_crates: HashMap<u32, ExternalCrate>,
3843
/// A single version number to be used in the future when making backwards incompatible changes
3944
/// to the JSON output.
4045
pub format_version: u32,
@@ -95,7 +100,7 @@ pub struct Item {
95100
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
96101
pub docs: Option<String>,
97102
/// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs
98-
pub links: FxHashMap<String, Id>,
103+
pub links: HashMap<String, Id>,
99104
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
100105
pub attrs: Vec<String>,
101106
/// Information about the item’s deprecation, if present.

0 commit comments

Comments
 (0)