about summary refs log tree commit diff
path: root/src/librustdoc/html/render/search_index.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-22 08:52:53 +0000
committerbors <bors@rust-lang.org>2025-07-22 08:52:53 +0000
commit1a8eaa852507b134fcd0557547b35308273b4b74 (patch)
tree5656ed7794f557ce02b603c2aebafeeef5e4c31a /src/librustdoc/html/render/search_index.rs
parent9748d87dc70a9a6725c5dbd76ce29d04752b4f90 (diff)
parent8a5bcdde9d8668f92bd2f323898d5da1bdc5df5b (diff)
downloadrust-try.tar.gz
rust-try.zip
Auto merge of #144287 - nnethercote:Symbol-with_interner, r=<try> try
Introduce `Symbol::with_interner`.

It lets you get the contents of multiple symbols with a single TLS lookup and interner lock, instead of one per symbol.

r? `@ghost`
Diffstat (limited to 'src/librustdoc/html/render/search_index.rs')
-rw-r--r--src/librustdoc/html/render/search_index.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 3c9be29ccc3..6f1765a598b 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -105,12 +105,16 @@ pub(crate) fn build_index(
     let mut aliases: BTreeMap<String, Vec<usize>> = BTreeMap::new();
 
     // Sort search index items. This improves the compressibility of the search index.
-    cache.search_index.sort_unstable_by(|k1, k2| {
-        // `sort_unstable_by_key` produces lifetime errors
-        // HACK(rustdoc): should not be sorting `CrateNum` or `DefIndex`, this will soon go away, too
-        let k1 = (&k1.path, k1.name.as_str(), &k1.ty, k1.parent.map(|id| (id.index, id.krate)));
-        let k2 = (&k2.path, k2.name.as_str(), &k2.ty, k2.parent.map(|id| (id.index, id.krate)));
-        Ord::cmp(&k1, &k2)
+    Symbol::with_interner(|inner| {
+        cache.search_index.sort_unstable_by(|k1, k2| {
+            // `sort_unstable_by_key` produces lifetime errors
+            // HACK(rustdoc): should not be sorting `CrateNum` or `DefIndex`, this will soon go
+            // away, too
+            let pair = |k: &IndexItem| k.parent.map(|id| (id.index, id.krate));
+            let k1 = (&k1.path, inner.get_str(k1.name), &k1.ty, pair(k1));
+            let k2 = (&k2.path, inner.get_str(k2.name), &k2.ty, pair(k2));
+            Ord::cmp(&k1, &k2)
+        });
     });
 
     // Set up alias indexes.