@@ -18,28 +18,28 @@ if (!Array.prototype.toSpliced) {
18
18
// This mapping table should match the discriminants of
19
19
// `rustdoc::formats::item_type::ItemType` type in Rust.
20
20
const itemTypes = [
21
+ "keyword" ,
22
+ "primitive" ,
21
23
"mod" ,
22
24
"externcrate" ,
23
25
"import" ,
24
- "struct" ,
26
+ "struct" , // 5
25
27
"enum" ,
26
- "fn" , // 5
28
+ "fn" ,
27
29
"type" ,
28
30
"static" ,
29
- "trait" ,
31
+ "trait" , // 10
30
32
"impl" ,
31
- "tymethod" , // 10
33
+ "tymethod" ,
32
34
"method" ,
33
35
"structfield" ,
34
- "variant" ,
36
+ "variant" , // 15
35
37
"macro" ,
36
- "primitive" , // 15
37
38
"associatedtype" ,
38
39
"constant" ,
39
40
"associatedconstant" ,
40
- "union" ,
41
- "foreigntype" , // 20
42
- "keyword" ,
41
+ "union" , // 20
42
+ "foreigntype" ,
43
43
"existential" ,
44
44
"attr" ,
45
45
"derive" ,
@@ -48,6 +48,8 @@ const itemTypes = [
48
48
] ;
49
49
50
50
const longItemTypes = [
51
+ "keyword" ,
52
+ "primitive type" ,
51
53
"module" ,
52
54
"extern crate" ,
53
55
"re-export" ,
@@ -63,22 +65,18 @@ const longItemTypes = [
63
65
"struct field" ,
64
66
"enum variant" ,
65
67
"macro" ,
66
- "primitive type" ,
67
68
"assoc type" ,
68
69
"constant" ,
69
70
"assoc const" ,
70
71
"union" ,
71
72
"foreign type" ,
72
- "keyword" ,
73
73
"existential type" ,
74
74
"attribute macro" ,
75
75
"derive macro" ,
76
76
"trait alias" ,
77
77
] ;
78
78
79
79
// used for special search precedence
80
- const TY_PRIMITIVE = itemTypes . indexOf ( "primitive" ) ;
81
- const TY_KEYWORD = itemTypes . indexOf ( "keyword" ) ;
82
80
const TY_GENERIC = itemTypes . indexOf ( "generic" ) ;
83
81
const ROOT_PATH = typeof window !== "undefined" ? window . rootPath : "../" ;
84
82
@@ -1317,16 +1315,6 @@ function initSearch(rawSearchIndex) {
1317
1315
return ( a > b ? + 1 : - 1 ) ;
1318
1316
}
1319
1317
1320
- // special precedence for primitive and keyword pages
1321
- if ( ( aaa . item . ty === TY_PRIMITIVE && bbb . item . ty !== TY_KEYWORD ) ||
1322
- ( aaa . item . ty === TY_KEYWORD && bbb . item . ty !== TY_PRIMITIVE ) ) {
1323
- return - 1 ;
1324
- }
1325
- if ( ( bbb . item . ty === TY_PRIMITIVE && aaa . item . ty !== TY_PRIMITIVE ) ||
1326
- ( bbb . item . ty === TY_KEYWORD && aaa . item . ty !== TY_KEYWORD ) ) {
1327
- return 1 ;
1328
- }
1329
-
1330
1318
// sort by description (no description goes later)
1331
1319
a = ( aaa . item . desc === "" ) ;
1332
1320
b = ( bbb . item . desc === "" ) ;
@@ -1840,26 +1828,16 @@ function initSearch(rawSearchIndex) {
1840
1828
1841
1829
const length = path . length ;
1842
1830
const clength = contains . length ;
1843
- if ( clength > length ) {
1844
- return maxEditDistance + 1 ;
1845
- }
1846
- for ( let i = 0 ; i < length ; ++ i ) {
1847
- if ( i + clength > length ) {
1848
- break ;
1849
- }
1831
+ pathiter: for ( let i = length - clength ; i >= 0 ; i -= 1 ) {
1850
1832
let dist_total = 0 ;
1851
- let aborted = false ;
1852
1833
for ( let x = 0 ; x < clength ; ++ x ) {
1853
1834
const dist = editDistance ( path [ i + x ] , contains [ x ] , maxEditDistance ) ;
1854
1835
if ( dist > maxEditDistance ) {
1855
- aborted = true ;
1856
- break ;
1836
+ continue pathiter;
1857
1837
}
1858
1838
dist_total += dist ;
1859
1839
}
1860
- if ( ! aborted ) {
1861
- ret_dist = Math . min ( ret_dist , Math . round ( dist_total / clength ) ) ;
1862
- }
1840
+ ret_dist = Math . min ( ret_dist , Math . round ( dist_total / clength ) ) ;
1863
1841
}
1864
1842
return ret_dist ;
1865
1843
}
@@ -2953,7 +2931,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
2953
2931
// https://mathiasbynens.be/notes/shapes-ics
2954
2932
const crateRow = {
2955
2933
crate : crate ,
2956
- ty : 1 , // == ExternCrate
2934
+ ty : 3 , // == ExternCrate
2957
2935
name : crate ,
2958
2936
path : "" ,
2959
2937
desc : crateCorpus . doc ,
0 commit comments