diff options
| author | Jalil David Salamé Messina <jalil.salame@gmail.com> | 2024-10-19 17:48:06 +0200 |
|---|---|---|
| committer | Jalil David Salamé Messina <jalil.salame@gmail.com> | 2024-10-19 18:15:09 +0200 |
| commit | d1fa49b2e66c343210c413b68ed57f150b7b89d8 (patch) | |
| tree | 2646f634bea236ce9d875024e85f3f6d03ae2c4b | |
| parent | c926476d013fbb2ca43bd5259d0a7228009a9cb2 (diff) | |
| download | rust-d1fa49b2e66c343210c413b68ed57f150b7b89d8.tar.gz rust-d1fa49b2e66c343210c413b68ed57f150b7b89d8.zip | |
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
| -rw-r--r-- | src/rustdoc-json-types/Cargo.toml | 5 | ||||
| -rw-r--r-- | src/rustdoc-json-types/lib.rs | 15 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/rustdoc-json-types/Cargo.toml b/src/rustdoc-json-types/Cargo.toml index d3548036d4c..7f7cd3672b7 100644 --- a/src/rustdoc-json-types/Cargo.toml +++ b/src/rustdoc-json-types/Cargo.toml @@ -6,9 +6,12 @@ edition = "2021" [lib] path = "lib.rs" +[features] +default = ["rustc-hash"] + [dependencies] serde = { version = "1.0", features = ["derive"] } -rustc-hash = "1.1.0" +rustc-hash = { version = "1.1.0", optional = true } [dev-dependencies] serde_json = "1.0" diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index b0bedab495f..c4e142342a8 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -3,11 +3,16 @@ //! These types are the public API exposed through the `--output-format json` flag. The [`Crate`] //! struct is the root of the JSON blob and all other items are contained within. +#[cfg(not(feature = "rustc-hash"))] +use std::collections::HashMap; use std::path::PathBuf; -pub use rustc_hash::FxHashMap; +#[cfg(feature = "rustc-hash")] +use rustc_hash::FxHashMap as HashMap; use serde::{Deserialize, Serialize}; +pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc + /// The version of JSON output that this crate represents. /// /// This integer is incremented with every breaking change to the API, @@ -30,11 +35,11 @@ pub struct Crate { pub includes_private: bool, /// A collection of all items in the local crate as well as some external traits and their /// items that are referenced locally. - pub index: FxHashMap<Id, Item>, + pub index: HashMap<Id, Item>, /// Maps IDs to fully qualified paths and other info helpful for generating links. - pub paths: FxHashMap<Id, ItemSummary>, + pub paths: HashMap<Id, ItemSummary>, /// Maps `crate_id` of items to a crate name and html_root_url if it exists. - pub external_crates: FxHashMap<u32, ExternalCrate>, + pub external_crates: HashMap<u32, ExternalCrate>, /// A single version number to be used in the future when making backwards incompatible changes /// to the JSON output. pub format_version: u32, @@ -95,7 +100,7 @@ pub struct Item { /// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`). pub docs: Option<String>, /// 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 - pub links: FxHashMap<String, Id>, + pub links: HashMap<String, Id>, /// Stringified versions of the attributes on this item (e.g. `"#[inline]"`) pub attrs: Vec<String>, /// Information about the item’s deprecation, if present. |
