Skip to content

Commit f1a3494

Browse files
authored
Rollup merge of #108013 - notriddle:notriddle/search-index-itemtype, r=GuillaumeGomez
rustdoc: use a string with one-character codes for search index types $ wc -c search-index.old.js search-index.new.js 3940530 search-index.old.js 3843222 search-index.new.js ((3940530-3843222)/3940530)*100 = 2.47% $ wc -c search-index.old.js.gz search-index.new.js.gz 380251 search-index.old.js.gz 379434 search-index.new.js.gz ((380251-379434)/380251)*100 = 0.214%
2 parents 9bf807e + a7b69dd commit f1a3494

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/librustdoc/formats/item_type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::clean;
2121
/// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
2222
/// ordering based on a helper function inside `item_module`, in the same file.
2323
#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)]
24+
#[repr(u8)]
2425
pub(crate) enum ItemType {
2526
Module = 0,
2627
ExternCrate = 1,

src/librustdoc/html/render/search_index.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,16 @@ pub(crate) fn build_index<'tcx>(
236236
crate_data.serialize_field("doc", &self.doc)?;
237237
crate_data.serialize_field(
238238
"t",
239-
&self.items.iter().map(|item| &item.ty).collect::<Vec<_>>(),
239+
&self
240+
.items
241+
.iter()
242+
.map(|item| {
243+
let n = item.ty as u8;
244+
let c = char::try_from(n + b'A').expect("item types must fit in ASCII");
245+
assert!(c <= 'z', "item types must fit within ASCII printables");
246+
c
247+
})
248+
.collect::<String>(),
240249
)?;
241250
crate_data.serialize_field(
242251
"n",

src/librustdoc/html/static/js/search.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ function initSearch(rawSearchIndex) {
19391939
* @type {Array<string>}
19401940
*/
19411941
const searchWords = [];
1942+
const charA = "A".charCodeAt(0);
19421943
let i, word;
19431944
let currentIndex = 0;
19441945
let id = 0;
@@ -1953,7 +1954,7 @@ function initSearch(rawSearchIndex) {
19531954
/**
19541955
* The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f`
19551956
* are arrays with the same length. n[i] contains the name of an item.
1956-
* t[i] contains the type of that item (as a small integer that represents an
1957+
* t[i] contains the type of that item (as a string of characters that represent an
19571958
* offset in `itemTypes`). d[i] contains the description of that item.
19581959
*
19591960
* q[i] contains the full path of the item, or an empty string indicating
@@ -1980,7 +1981,7 @@ function initSearch(rawSearchIndex) {
19801981
* doc: string,
19811982
* a: Object,
19821983
* n: Array<string>,
1983-
* t: Array<Number>,
1984+
* t: String,
19841985
* d: Array<string>,
19851986
* q: Array<string>,
19861987
* i: Array<Number>,
@@ -2009,7 +2010,7 @@ function initSearch(rawSearchIndex) {
20092010
searchIndex.push(crateRow);
20102011
currentIndex += 1;
20112012

2012-
// an array of (Number) item types
2013+
// a String of one character item type codes
20132014
const itemTypes = crateCorpus.t;
20142015
// an array of (String) item names
20152016
const itemNames = crateCorpus.n;
@@ -2060,7 +2061,7 @@ function initSearch(rawSearchIndex) {
20602061
}
20612062
const row = {
20622063
crate: crate,
2063-
ty: itemTypes[i],
2064+
ty: itemTypes.charCodeAt(i) - charA,
20642065
name: itemNames[i],
20652066
path: itemPaths[i] ? itemPaths[i] : lastPath,
20662067
desc: itemDescs[i],

0 commit comments

Comments
 (0)