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%
This commit is contained in:
parent
0b439b119b
commit
a7b69ddea9
3 changed files with 16 additions and 5 deletions
|
@ -21,6 +21,7 @@ use crate::clean;
|
||||||
/// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
|
/// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
|
||||||
/// ordering based on a helper function inside `item_module`, in the same file.
|
/// ordering based on a helper function inside `item_module`, in the same file.
|
||||||
#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)]
|
#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)]
|
||||||
|
#[repr(u8)]
|
||||||
pub(crate) enum ItemType {
|
pub(crate) enum ItemType {
|
||||||
Module = 0,
|
Module = 0,
|
||||||
ExternCrate = 1,
|
ExternCrate = 1,
|
||||||
|
|
|
@ -236,7 +236,16 @@ pub(crate) fn build_index<'tcx>(
|
||||||
crate_data.serialize_field("doc", &self.doc)?;
|
crate_data.serialize_field("doc", &self.doc)?;
|
||||||
crate_data.serialize_field(
|
crate_data.serialize_field(
|
||||||
"t",
|
"t",
|
||||||
&self.items.iter().map(|item| &item.ty).collect::<Vec<_>>(),
|
&self
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.map(|item| {
|
||||||
|
let n = item.ty as u8;
|
||||||
|
let c = char::try_from(n + b'A').expect("item types must fit in ASCII");
|
||||||
|
assert!(c <= 'z', "item types must fit within ASCII printables");
|
||||||
|
c
|
||||||
|
})
|
||||||
|
.collect::<String>(),
|
||||||
)?;
|
)?;
|
||||||
crate_data.serialize_field(
|
crate_data.serialize_field(
|
||||||
"n",
|
"n",
|
||||||
|
|
|
@ -1939,6 +1939,7 @@ function initSearch(rawSearchIndex) {
|
||||||
* @type {Array<string>}
|
* @type {Array<string>}
|
||||||
*/
|
*/
|
||||||
const searchWords = [];
|
const searchWords = [];
|
||||||
|
const charA = "A".charCodeAt(0);
|
||||||
let i, word;
|
let i, word;
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
let id = 0;
|
let id = 0;
|
||||||
|
@ -1953,7 +1954,7 @@ function initSearch(rawSearchIndex) {
|
||||||
/**
|
/**
|
||||||
* The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f`
|
* The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f`
|
||||||
* are arrays with the same length. n[i] contains the name of an item.
|
* are arrays with the same length. n[i] contains the name of an item.
|
||||||
* t[i] contains the type of that item (as a small integer that represents an
|
* t[i] contains the type of that item (as a string of characters that represent an
|
||||||
* offset in `itemTypes`). d[i] contains the description of that item.
|
* offset in `itemTypes`). d[i] contains the description of that item.
|
||||||
*
|
*
|
||||||
* q[i] contains the full path of the item, or an empty string indicating
|
* q[i] contains the full path of the item, or an empty string indicating
|
||||||
|
@ -1980,7 +1981,7 @@ function initSearch(rawSearchIndex) {
|
||||||
* doc: string,
|
* doc: string,
|
||||||
* a: Object,
|
* a: Object,
|
||||||
* n: Array<string>,
|
* n: Array<string>,
|
||||||
* t: Array<Number>,
|
* t: String,
|
||||||
* d: Array<string>,
|
* d: Array<string>,
|
||||||
* q: Array<string>,
|
* q: Array<string>,
|
||||||
* i: Array<Number>,
|
* i: Array<Number>,
|
||||||
|
@ -2009,7 +2010,7 @@ function initSearch(rawSearchIndex) {
|
||||||
searchIndex.push(crateRow);
|
searchIndex.push(crateRow);
|
||||||
currentIndex += 1;
|
currentIndex += 1;
|
||||||
|
|
||||||
// an array of (Number) item types
|
// a String of one character item type codes
|
||||||
const itemTypes = crateCorpus.t;
|
const itemTypes = crateCorpus.t;
|
||||||
// an array of (String) item names
|
// an array of (String) item names
|
||||||
const itemNames = crateCorpus.n;
|
const itemNames = crateCorpus.n;
|
||||||
|
@ -2060,7 +2061,7 @@ function initSearch(rawSearchIndex) {
|
||||||
}
|
}
|
||||||
const row = {
|
const row = {
|
||||||
crate: crate,
|
crate: crate,
|
||||||
ty: itemTypes[i],
|
ty: itemTypes.charCodeAt(i) - charA,
|
||||||
name: itemNames[i],
|
name: itemNames[i],
|
||||||
path: itemPaths[i] ? itemPaths[i] : lastPath,
|
path: itemPaths[i] ? itemPaths[i] : lastPath,
|
||||||
desc: itemDescs[i],
|
desc: itemDescs[i],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue