Skip to content

Commit 0405652

Browse files
authored
Rollup merge of rust-lang#127379 - notriddle:notriddle/decode, r=GuillaumeGomez
rustdoc-search: stop constructing pointless arrays in decode I'm not sure why I ever thought that would be okay. This is clearly hot code, and should avoid Array.prototype.map when it's not needed. In any case, it shows up in the profiler. rustdoc-js-profiler: https://notriddle.com/rustdoc-html-demo-11/decode-opt-1/index.html Firefox profiler: [Before](https://share.firefox.dev/3RRH2fR) [After](https://share.firefox.dev/3Wblcq8)
2 parents 2137d19 + fbb6300 commit 0405652

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -3293,10 +3293,9 @@ ${item.displayPath}<span class="${type}">${name}</span>\
32933293
}
32943294
// call after consuming `{`
32953295
decodeList() {
3296-
const cb = "}".charCodeAt(0);
32973296
let c = this.string.charCodeAt(this.offset);
32983297
const ret = [];
3299-
while (c !== cb) {
3298+
while (c !== 125) { // 125 = "}"
33003299
ret.push(this.decode());
33013300
c = this.string.charCodeAt(this.offset);
33023301
}
@@ -3305,14 +3304,13 @@ ${item.displayPath}<span class="${type}">${name}</span>\
33053304
}
33063305
// consumes and returns a list or integer
33073306
decode() {
3308-
const [ob, la] = ["{", "`"].map(c => c.charCodeAt(0));
33093307
let n = 0;
33103308
let c = this.string.charCodeAt(this.offset);
3311-
if (c === ob) {
3309+
if (c === 123) { // 123 = "{"
33123310
this.offset += 1;
33133311
return this.decodeList();
33143312
}
3315-
while (c < la) {
3313+
while (c < 96) { // 96 = "`"
33163314
n = (n << 4) | (c & 0xF);
33173315
this.offset += 1;
33183316
c = this.string.charCodeAt(this.offset);
@@ -3325,15 +3323,14 @@ ${item.displayPath}<span class="${type}">${name}</span>\
33253323
}
33263324
next() {
33273325
const c = this.string.charCodeAt(this.offset);
3328-
const [zero, ua, la] = ["0", "@", "`"].map(c => c.charCodeAt(0));
33293326
// sixteen characters after "0" are backref
3330-
if (c >= zero && c < ua) {
3327+
if (c >= 48 && c < 64) { // 48 = "0", 64 = "@"
33313328
this.offset += 1;
3332-
return this.backrefQueue[c - zero];
3329+
return this.backrefQueue[c - 48];
33333330
}
33343331
// special exception: 0 doesn't use backref encoding
33353332
// it's already one character, and it's always nullish
3336-
if (c === la) {
3333+
if (c === 96) { // 96 = "`"
33373334
this.offset += 1;
33383335
return this.cons(0);
33393336
}
@@ -3472,7 +3469,6 @@ ${item.displayPath}<span class="${type}">${name}</span>\
34723469
searchIndex = [];
34733470
searchIndexDeprecated = new Map();
34743471
searchIndexEmptyDesc = new Map();
3475-
const charA = "A".charCodeAt(0);
34763472
let currentIndex = 0;
34773473
let id = 0;
34783474

@@ -3639,7 +3635,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
36393635
// object defined above.
36403636
const row = {
36413637
crate,
3642-
ty: itemTypes.charCodeAt(i) - charA,
3638+
ty: itemTypes.charCodeAt(i) - 65, // 65 = "A"
36433639
name: itemNames[i],
36443640
path,
36453641
descShard,

0 commit comments

Comments
 (0)