Skip to content

Commit 6a4bdda

Browse files
Reduce js files size
1 parent 72b7c8d commit 6a4bdda

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

src/librustdoc/html/render.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ impl ToJson for Type {
413413
match self.name {
414414
Some(ref name) => {
415415
let mut data = BTreeMap::new();
416-
data.insert("name".to_owned(), name.to_json());
416+
data.insert("n".to_owned(), name.to_json());
417417
if let Some(ref generics) = self.generics {
418-
data.insert("generics".to_owned(), generics.to_json());
418+
data.insert("g".to_owned(), generics.to_json());
419419
}
420420
Json::Object(data)
421421
},
@@ -438,8 +438,12 @@ impl ToJson for IndexItemFunctionType {
438438
Json::Null
439439
} else {
440440
let mut data = BTreeMap::new();
441-
data.insert("inputs".to_owned(), self.inputs.to_json());
442-
data.insert("output".to_owned(), self.output.to_json());
441+
if !self.inputs.is_empty() {
442+
data.insert("i".to_owned(), self.inputs.to_json());
443+
}
444+
if let Some(ref output) = self.output {
445+
data.insert("o".to_owned(), output.to_json());
446+
}
443447
Json::Object(data)
444448
}
445449
}
@@ -897,8 +901,8 @@ themePicker.onblur = handleThemeButtonsBlur;
897901
}
898902

899903
fn show_item(item: &IndexItem, krate: &str) -> String {
900-
format!("{{'crate':'{}','ty':{},'name':'{}','desc':'{}','path':'{}'{}}}",
901-
krate, item.ty as usize, item.name, item.desc, item.path,
904+
format!("{{'crate':'{}','ty':{},'name':'{}','desc':'{}','p':'{}'{}}}",
905+
krate, item.ty as usize, item.name, item.desc.replace("'", "\\'"), item.path,
902906
if let Some(p) = item.parent_idx {
903907
format!(",'parent':{}", p)
904908
} else {

src/librustdoc/html/static/main.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
if (isType !== true || obj.type) {
463463
var res = buildHrefAndPath(obj);
464464
obj.displayPath = pathSplitter(res[0]);
465-
obj.fullPath = obj.displayPath + obj.name;
465+
obj.fullPath = obj.displayPath + obj.n;
466466
obj.href = res[1];
467467
out.push(obj);
468468
if (out.length >= MAX_RESULTS) {
@@ -597,8 +597,8 @@
597597
// match as well.
598598
var lev_distance = MAX_LEV_DISTANCE + 1;
599599
if (val.generics.length > 0) {
600-
if (obj.generics && obj.generics.length >= val.generics.length) {
601-
var elems = obj.generics.slice(0);
600+
if (obj.g && obj.g.length >= val.generics.length) {
601+
var elems = obj.g.slice(0);
602602
var total = 0;
603603
var done = 0;
604604
// We need to find the type that matches the most to remove it in order
@@ -630,11 +630,11 @@
630630
// Check for type name and type generics (if any).
631631
function checkType(obj, val, literalSearch) {
632632
var lev_distance = MAX_LEV_DISTANCE + 1;
633-
if (obj.name === val.name) {
633+
if (obj.n === val.name) {
634634
if (literalSearch === true) {
635635
if (val.generics && val.generics.length !== 0) {
636-
if (obj.generics && obj.length >= val.generics.length) {
637-
var elems = obj.generics.slice(0);
636+
if (obj.g && obj.length >= val.generics.length) {
637+
var elems = obj.g.slice(0);
638638
var allFound = true;
639639
var x;
640640

@@ -658,7 +658,7 @@
658658
}
659659
// If the type has generics but don't match, then it won't return at this point.
660660
// Otherwise, `checkGenerics` will return 0 and it'll return.
661-
if (obj.generics && obj.generics.length !== 0) {
661+
if (obj.g && obj.g.length !== 0) {
662662
var tmp_lev = checkGenerics(obj, val);
663663
if (tmp_lev <= MAX_LEV_DISTANCE) {
664664
return tmp_lev;
@@ -669,22 +669,22 @@
669669
}
670670
// Names didn't match so let's check if one of the generic types could.
671671
if (literalSearch === true) {
672-
if (obj.generics && obj.generics.length > 0) {
673-
for (var x = 0; x < obj.generics.length; ++x) {
674-
if (obj.generics[x] === val.name) {
672+
if (obj.g && obj.g.length > 0) {
673+
for (var x = 0; x < obj.g.length; ++x) {
674+
if (obj.g[x] === val.name) {
675675
return true;
676676
}
677677
}
678678
}
679679
return false;
680680
}
681-
var lev_distance = Math.min(levenshtein(obj.name, val.name), lev_distance);
681+
var lev_distance = Math.min(levenshtein(obj.n, val.name), lev_distance);
682682
if (lev_distance <= MAX_LEV_DISTANCE) {
683683
lev_distance = Math.min(checkGenerics(obj, val), lev_distance);
684-
} else if (obj.generics && obj.generics.length > 0) {
684+
} else if (obj.g && obj.g.length > 0) {
685685
// We can check if the type we're looking for is inside the generics!
686-
for (var x = 0; x < obj.generics.length; ++x) {
687-
lev_distance = Math.min(levenshtein(obj.generics[x], val.name),
686+
for (var x = 0; x < obj.g.length; ++x) {
687+
lev_distance = Math.min(levenshtein(obj.g[x], val.name),
688688
lev_distance);
689689
}
690690
}
@@ -696,9 +696,9 @@
696696
function findArg(obj, val, literalSearch) {
697697
var lev_distance = MAX_LEV_DISTANCE + 1;
698698

699-
if (obj && obj.type && obj.type.inputs.length > 0) {
700-
for (var i = 0; i < obj.type.inputs.length; i++) {
701-
var tmp = checkType(obj.type.inputs[i], val, literalSearch);
699+
if (obj && obj.type && obj.type.i && obj.type.i.length > 0) {
700+
for (var i = 0; i < obj.type.i.length; i++) {
701+
var tmp = checkType(obj.type.i[i], val, literalSearch);
702702
if (literalSearch === true && tmp === true) {
703703
return true;
704704
}
@@ -714,8 +714,8 @@
714714
function checkReturned(obj, val, literalSearch) {
715715
var lev_distance = MAX_LEV_DISTANCE + 1;
716716

717-
if (obj && obj.type && obj.type.output) {
718-
var tmp = checkType(obj.type.output, val, literalSearch);
717+
if (obj && obj.type && obj.type.o) {
718+
var tmp = checkType(obj.type.o, val, literalSearch);
719719
if (literalSearch === true && tmp === true) {
720720
return true;
721721
}
@@ -860,7 +860,7 @@
860860
var fullId = generateId(ty);
861861

862862
// allow searching for void (no output) functions as well
863-
var typeOutput = type.output ? type.output.name : "";
863+
var typeOutput = type.o ? type.o.name : "";
864864
var returned = checkReturned(ty, output, true);
865865
if (output.name === "*" || returned === true) {
866866
var in_args = false;
@@ -1029,6 +1029,7 @@
10291029
for (var i = 0; i < aliases.length; ++i) {
10301030
aliases[i].is_alias = true;
10311031
aliases[i].alias = query.raw;
1032+
aliases[i].path = aliases[i].p;
10321033
var res = buildHrefAndPath(aliases[i]);
10331034
aliases[i].displayPath = pathSplitter(res[0]);
10341035
aliases[i].fullPath = aliases[i].displayPath + aliases[i].name;

0 commit comments

Comments
 (0)