Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b8371c8

Browse files
authoredDec 2, 2024
Unrolled build for rust-lang#133745
Rollup merge of rust-lang#133745 - GuillaumeGomez:default-ids-match, r=notriddle Remove static HashSet for default IDs list Follow-up of rust-lang#133345. Let's see how it impacts performance. r? `@notriddle`
2 parents 32eea2f + b863c0d commit b8371c8

File tree

1 file changed

+56
-60
lines changed

1 file changed

+56
-60
lines changed
 

‎src/librustdoc/html/markdown.rs

+56-60
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ use std::iter::Peekable;
3232
use std::ops::{ControlFlow, Range};
3333
use std::path::PathBuf;
3434
use std::str::{self, CharIndices};
35-
use std::sync::OnceLock;
3635

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

18831882
#[derive(Clone, Default, Debug)]
18841883
pub struct IdMap {
1885-
map: FxHashMap<Cow<'static, str>, usize>,
1884+
map: FxHashMap<String, usize>,
18861885
existing_footnotes: usize,
18871886
}
18881887

1889-
// The map is pre-initialized and then can be used as is to prevent cloning it for each item
1890-
// (in the sidebar rendering).
1891-
static DEFAULT_ID_MAP: OnceLock<FxHashSet<&'static str>> = OnceLock::new();
1892-
1893-
fn init_id_map() -> FxHashSet<&'static str> {
1894-
let mut map = FxHashSet::default();
1895-
// This is the list of IDs used in JavaScript.
1896-
map.insert("help");
1897-
map.insert("settings");
1898-
map.insert("not-displayed");
1899-
map.insert("alternative-display");
1900-
map.insert("search");
1901-
map.insert("crate-search");
1902-
map.insert("crate-search-div");
1903-
// This is the list of IDs used in HTML generated in Rust (including the ones
1904-
// used in tera template files).
1905-
map.insert("themeStyle");
1906-
map.insert("settings-menu");
1907-
map.insert("help-button");
1908-
map.insert("sidebar-button");
1909-
map.insert("main-content");
1910-
map.insert("toggle-all-docs");
1911-
map.insert("all-types");
1912-
map.insert("default-settings");
1913-
map.insert("sidebar-vars");
1914-
map.insert("copy-path");
1915-
map.insert("rustdoc-toc");
1916-
map.insert("rustdoc-modnav");
1917-
// This is the list of IDs used by rustdoc sections (but still generated by
1918-
// rustdoc).
1919-
map.insert("fields");
1920-
map.insert("variants");
1921-
map.insert("implementors-list");
1922-
map.insert("synthetic-implementors-list");
1923-
map.insert("foreign-impls");
1924-
map.insert("implementations");
1925-
map.insert("trait-implementations");
1926-
map.insert("synthetic-implementations");
1927-
map.insert("blanket-implementations");
1928-
map.insert("required-associated-types");
1929-
map.insert("provided-associated-types");
1930-
map.insert("provided-associated-consts");
1931-
map.insert("required-associated-consts");
1932-
map.insert("required-methods");
1933-
map.insert("provided-methods");
1934-
map.insert("dyn-compatibility");
1935-
map.insert("implementors");
1936-
map.insert("synthetic-implementors");
1937-
map.insert("implementations-list");
1938-
map.insert("trait-implementations-list");
1939-
map.insert("synthetic-implementations-list");
1940-
map.insert("blanket-implementations-list");
1941-
map.insert("deref-methods");
1942-
map.insert("layout");
1943-
map.insert("aliased-type");
1944-
map
1888+
fn is_default_id(id: &str) -> bool {
1889+
matches!(
1890+
id,
1891+
// This is the list of IDs used in JavaScript.
1892+
"help"
1893+
| "settings"
1894+
| "not-displayed"
1895+
| "alternative-display"
1896+
| "search"
1897+
| "crate-search"
1898+
| "crate-search-div"
1899+
// This is the list of IDs used in HTML generated in Rust (including the ones
1900+
// used in tera template files).
1901+
| "themeStyle"
1902+
| "settings-menu"
1903+
| "help-button"
1904+
| "sidebar-button"
1905+
| "main-content"
1906+
| "toggle-all-docs"
1907+
| "all-types"
1908+
| "default-settings"
1909+
| "sidebar-vars"
1910+
| "copy-path"
1911+
| "rustdoc-toc"
1912+
| "rustdoc-modnav"
1913+
// This is the list of IDs used by rustdoc sections (but still generated by
1914+
// rustdoc).
1915+
| "fields"
1916+
| "variants"
1917+
| "implementors-list"
1918+
| "synthetic-implementors-list"
1919+
| "foreign-impls"
1920+
| "implementations"
1921+
| "trait-implementations"
1922+
| "synthetic-implementations"
1923+
| "blanket-implementations"
1924+
| "required-associated-types"
1925+
| "provided-associated-types"
1926+
| "provided-associated-consts"
1927+
| "required-associated-consts"
1928+
| "required-methods"
1929+
| "provided-methods"
1930+
| "dyn-compatibility"
1931+
| "implementors"
1932+
| "synthetic-implementors"
1933+
| "implementations-list"
1934+
| "trait-implementations-list"
1935+
| "synthetic-implementations-list"
1936+
| "blanket-implementations-list"
1937+
| "deref-methods"
1938+
| "layout"
1939+
| "aliased-type"
1940+
)
19451941
}
19461942

19471943
impl IdMap {
@@ -1953,7 +1949,7 @@ impl IdMap {
19531949
let id = match self.map.get_mut(candidate.as_ref()) {
19541950
None => {
19551951
let candidate = candidate.to_string();
1956-
if DEFAULT_ID_MAP.get_or_init(init_id_map).contains(candidate.as_str()) {
1952+
if is_default_id(&candidate) {
19571953
let id = format!("{}-{}", candidate, 1);
19581954
self.map.insert(candidate.into(), 2);
19591955
id

0 commit comments

Comments
 (0)
Failed to load comments.