Skip to content

Commit

Permalink
Rollup merge of rust-lang#133745 - GuillaumeGomez:default-ids-match, …
Browse files Browse the repository at this point in the history
…r=notriddle

Remove static HashSet for default IDs list

Follow-up of rust-lang#133345.

Let's see how it impacts performance.

r? `@notriddle`
  • Loading branch information
GuillaumeGomez authored Dec 2, 2024
2 parents ed08803 + b863c0d commit 7145e4e
Showing 1 changed file with 56 additions and 60 deletions.
116 changes: 56 additions & 60 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ use std::iter::Peekable;
use std::ops::{ControlFlow, Range};
use std::path::PathBuf;
use std::str::{self, CharIndices};
use std::sync::OnceLock;

use pulldown_cmark::{
BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag, TagEnd, html,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Diag, DiagMessage};
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -1882,66 +1881,63 @@ pub(crate) fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<Rust

#[derive(Clone, Default, Debug)]
pub struct IdMap {
map: FxHashMap<Cow<'static, str>, usize>,
map: FxHashMap<String, usize>,
existing_footnotes: usize,
}

// The map is pre-initialized and then can be used as is to prevent cloning it for each item
// (in the sidebar rendering).
static DEFAULT_ID_MAP: OnceLock<FxHashSet<&'static str>> = OnceLock::new();

fn init_id_map() -> FxHashSet<&'static str> {
let mut map = FxHashSet::default();
// This is the list of IDs used in JavaScript.
map.insert("help");
map.insert("settings");
map.insert("not-displayed");
map.insert("alternative-display");
map.insert("search");
map.insert("crate-search");
map.insert("crate-search-div");
// This is the list of IDs used in HTML generated in Rust (including the ones
// used in tera template files).
map.insert("themeStyle");
map.insert("settings-menu");
map.insert("help-button");
map.insert("sidebar-button");
map.insert("main-content");
map.insert("toggle-all-docs");
map.insert("all-types");
map.insert("default-settings");
map.insert("sidebar-vars");
map.insert("copy-path");
map.insert("rustdoc-toc");
map.insert("rustdoc-modnav");
// This is the list of IDs used by rustdoc sections (but still generated by
// rustdoc).
map.insert("fields");
map.insert("variants");
map.insert("implementors-list");
map.insert("synthetic-implementors-list");
map.insert("foreign-impls");
map.insert("implementations");
map.insert("trait-implementations");
map.insert("synthetic-implementations");
map.insert("blanket-implementations");
map.insert("required-associated-types");
map.insert("provided-associated-types");
map.insert("provided-associated-consts");
map.insert("required-associated-consts");
map.insert("required-methods");
map.insert("provided-methods");
map.insert("dyn-compatibility");
map.insert("implementors");
map.insert("synthetic-implementors");
map.insert("implementations-list");
map.insert("trait-implementations-list");
map.insert("synthetic-implementations-list");
map.insert("blanket-implementations-list");
map.insert("deref-methods");
map.insert("layout");
map.insert("aliased-type");
map
fn is_default_id(id: &str) -> bool {
matches!(
id,
// This is the list of IDs used in JavaScript.
"help"
| "settings"
| "not-displayed"
| "alternative-display"
| "search"
| "crate-search"
| "crate-search-div"
// This is the list of IDs used in HTML generated in Rust (including the ones
// used in tera template files).
| "themeStyle"
| "settings-menu"
| "help-button"
| "sidebar-button"
| "main-content"
| "toggle-all-docs"
| "all-types"
| "default-settings"
| "sidebar-vars"
| "copy-path"
| "rustdoc-toc"
| "rustdoc-modnav"
// This is the list of IDs used by rustdoc sections (but still generated by
// rustdoc).
| "fields"
| "variants"
| "implementors-list"
| "synthetic-implementors-list"
| "foreign-impls"
| "implementations"
| "trait-implementations"
| "synthetic-implementations"
| "blanket-implementations"
| "required-associated-types"
| "provided-associated-types"
| "provided-associated-consts"
| "required-associated-consts"
| "required-methods"
| "provided-methods"
| "dyn-compatibility"
| "implementors"
| "synthetic-implementors"
| "implementations-list"
| "trait-implementations-list"
| "synthetic-implementations-list"
| "blanket-implementations-list"
| "deref-methods"
| "layout"
| "aliased-type"
)
}

impl IdMap {
Expand All @@ -1953,7 +1949,7 @@ impl IdMap {
let id = match self.map.get_mut(candidate.as_ref()) {
None => {
let candidate = candidate.to_string();
if DEFAULT_ID_MAP.get_or_init(init_id_map).contains(candidate.as_str()) {
if is_default_id(&candidate) {
let id = format!("{}-{}", candidate, 1);
self.map.insert(candidate.into(), 2);
id
Expand Down

0 comments on commit 7145e4e

Please sign in to comment.