@@ -18,28 +18,28 @@ if (!Array.prototype.toSpliced) {
1818// This mapping table should match the discriminants of
1919// `rustdoc::formats::item_type::ItemType` type in Rust.
2020const itemTypes = [
21+ "keyword" ,
22+ "primitive" ,
2123 "mod" ,
2224 "externcrate" ,
2325 "import" ,
24- "struct" ,
26+ "struct" , // 5
2527 "enum" ,
26- "fn" , // 5
28+ "fn" ,
2729 "type" ,
2830 "static" ,
29- "trait" ,
31+ "trait" , // 10
3032 "impl" ,
31- "tymethod" , // 10
33+ "tymethod" ,
3234 "method" ,
3335 "structfield" ,
34- "variant" ,
36+ "variant" , // 15
3537 "macro" ,
36- "primitive" , // 15
3738 "associatedtype" ,
3839 "constant" ,
3940 "associatedconstant" ,
40- "union" ,
41- "foreigntype" , // 20
42- "keyword" ,
41+ "union" , // 20
42+ "foreigntype" ,
4343 "existential" ,
4444 "attr" ,
4545 "derive" ,
@@ -48,6 +48,8 @@ const itemTypes = [
4848] ;
4949
5050const longItemTypes = [
51+ "keyword" ,
52+ "primitive type" ,
5153 "module" ,
5254 "extern crate" ,
5355 "re-export" ,
@@ -63,22 +65,18 @@ const longItemTypes = [
6365 "struct field" ,
6466 "enum variant" ,
6567 "macro" ,
66- "primitive type" ,
6768 "assoc type" ,
6869 "constant" ,
6970 "assoc const" ,
7071 "union" ,
7172 "foreign type" ,
72- "keyword" ,
7373 "existential type" ,
7474 "attribute macro" ,
7575 "derive macro" ,
7676 "trait alias" ,
7777] ;
7878
7979// used for special search precedence
80- const TY_PRIMITIVE = itemTypes . indexOf ( "primitive" ) ;
81- const TY_KEYWORD = itemTypes . indexOf ( "keyword" ) ;
8280const TY_GENERIC = itemTypes . indexOf ( "generic" ) ;
8381const ROOT_PATH = typeof window !== "undefined" ? window . rootPath : "../" ;
8482
@@ -1317,16 +1315,6 @@ function initSearch(rawSearchIndex) {
13171315 return ( a > b ? + 1 : - 1 ) ;
13181316 }
13191317
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-
13301318 // sort by description (no description goes later)
13311319 a = ( aaa . item . desc === "" ) ;
13321320 b = ( bbb . item . desc === "" ) ;
@@ -1840,26 +1828,16 @@ function initSearch(rawSearchIndex) {
18401828
18411829 const length = path . length ;
18421830 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 ) {
18501832 let dist_total = 0 ;
1851- let aborted = false ;
18521833 for ( let x = 0 ; x < clength ; ++ x ) {
18531834 const dist = editDistance ( path [ i + x ] , contains [ x ] , maxEditDistance ) ;
18541835 if ( dist > maxEditDistance ) {
1855- aborted = true ;
1856- break ;
1836+ continue pathiter;
18571837 }
18581838 dist_total += dist ;
18591839 }
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 ) ) ;
18631841 }
18641842 return ret_dist ;
18651843 }
@@ -2953,7 +2931,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
29532931 // https://mathiasbynens.be/notes/shapes-ics
29542932 const crateRow = {
29552933 crate : crate ,
2956- ty : 1 , // == ExternCrate
2934+ ty : 3 , // == ExternCrate
29572935 name : crate ,
29582936 path : "" ,
29592937 desc : crateCorpus . doc ,
0 commit comments