Skip to content

Commit

Permalink
rustdoc-search: stop constructing pointless arrays in decode rust-lan…
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Aug 21, 2024
1 parent 9c22028 commit 864fe1b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,9 @@ class VlqHexDecoder {
}
// call after consuming `{`
decodeList() {
const cb = "}".charCodeAt(0);
let c = this.string.charCodeAt(this.offset);
const ret = [];
while (c !== cb) {
while (c !== 125) { // 125 = "}"
ret.push(this.decode());
c = this.string.charCodeAt(this.offset);
}
Expand All @@ -937,14 +936,13 @@ class VlqHexDecoder {
}
// consumes and returns a list or integer
decode() {
const [ob, la] = ["{", "`"].map(c => c.charCodeAt(0));
let n = 0;
let c = this.string.charCodeAt(this.offset);
if (c === ob) {
if (c === 123) { // 123 = "{"
this.offset += 1;
return this.decodeList();
}
while (c < la) {
while (c < 96) { // 96 = "`"
n = (n << 4) | (c & 0xF);
this.offset += 1;
c = this.string.charCodeAt(this.offset);
Expand All @@ -957,15 +955,14 @@ class VlqHexDecoder {
}
next() {
const c = this.string.charCodeAt(this.offset);
const [zero, ua, la] = ["0", "@", "`"].map(c => c.charCodeAt(0));
// sixteen characters after "0" are backref
if (c >= zero && c < ua) {
if (c >= 48 && c < 64) { // 48 = "0", 64 = "@"
this.offset += 1;
return this.backrefQueue[c - zero];
return this.backrefQueue[c - 48];
}
// special exception: 0 doesn't use backref encoding
// it's already one character, and it's always nullish
if (c === la) {
if (c === 96) { // 96 = "`"
this.offset += 1;
return this.cons(0);
}
Expand Down Expand Up @@ -1519,7 +1516,6 @@ class DocSearch {
};

const searchIndex = [];
const charA = "A".charCodeAt(0);
let currentIndex = 0;
let id = 0;

Expand Down Expand Up @@ -1685,7 +1681,7 @@ class DocSearch {
// object defined above.
const row = {
crate,
ty: itemTypes.charCodeAt(i) - charA,
ty: itemTypes.charCodeAt(i) - 65, // 65 = "A"
name: itemNames[i],
path,
descShard,
Expand Down

0 comments on commit 864fe1b

Please sign in to comment.