Skip to content

Commit 864fe1b

Browse files
committed
rustdoc-search: stop constructing pointless arrays in decode rust-lang#127379
1 parent 9c22028 commit 864fe1b

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
@@ -925,10 +925,9 @@ class VlqHexDecoder {
925925
}
926926
// call after consuming `{`
927927
decodeList() {
928-
const cb = "}".charCodeAt(0);
929928
let c = this.string.charCodeAt(this.offset);
930929
const ret = [];
931-
while (c !== cb) {
930+
while (c !== 125) { // 125 = "}"
932931
ret.push(this.decode());
933932
c = this.string.charCodeAt(this.offset);
934933
}
@@ -937,14 +936,13 @@ class VlqHexDecoder {
937936
}
938937
// consumes and returns a list or integer
939938
decode() {
940-
const [ob, la] = ["{", "`"].map(c => c.charCodeAt(0));
941939
let n = 0;
942940
let c = this.string.charCodeAt(this.offset);
943-
if (c === ob) {
941+
if (c === 123) { // 123 = "{"
944942
this.offset += 1;
945943
return this.decodeList();
946944
}
947-
while (c < la) {
945+
while (c < 96) { // 96 = "`"
948946
n = (n << 4) | (c & 0xF);
949947
this.offset += 1;
950948
c = this.string.charCodeAt(this.offset);
@@ -957,15 +955,14 @@ class VlqHexDecoder {
957955
}
958956
next() {
959957
const c = this.string.charCodeAt(this.offset);
960-
const [zero, ua, la] = ["0", "@", "`"].map(c => c.charCodeAt(0));
961958
// sixteen characters after "0" are backref
962-
if (c >= zero && c < ua) {
959+
if (c >= 48 && c < 64) { // 48 = "0", 64 = "@"
963960
this.offset += 1;
964-
return this.backrefQueue[c - zero];
961+
return this.backrefQueue[c - 48];
965962
}
966963
// special exception: 0 doesn't use backref encoding
967964
// it's already one character, and it's always nullish
968-
if (c === la) {
965+
if (c === 96) { // 96 = "`"
969966
this.offset += 1;
970967
return this.cons(0);
971968
}
@@ -1519,7 +1516,6 @@ class DocSearch {
15191516
};
15201517

15211518
const searchIndex = [];
1522-
const charA = "A".charCodeAt(0);
15231519
let currentIndex = 0;
15241520
let id = 0;
15251521

@@ -1685,7 +1681,7 @@ class DocSearch {
16851681
// object defined above.
16861682
const row = {
16871683
crate,
1688-
ty: itemTypes.charCodeAt(i) - charA,
1684+
ty: itemTypes.charCodeAt(i) - 65, // 65 = "A"
16891685
name: itemNames[i],
16901686
path,
16911687
descShard,

0 commit comments

Comments
 (0)