@@ -775,6 +775,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
775775 Json :: Object ( crate_data) )
776776}
777777
778+ const MINIFIED_VARIABLES : & str = "var N=null,E=\" \" ,T=\" t\" ,U=\" u\" ,searchIndex={};" ;
779+
778780fn write_shared (
779781 cx : & Context ,
780782 krate : & clean:: Crate ,
@@ -952,10 +954,11 @@ themePicker.onblur = handleThemeButtonsBlur;
952954 krate : & str ,
953955 key : & str ,
954956 for_search_index : bool ,
955- ) -> io:: Result < ( Vec < String > , Vec < String > , Vec < String > ) > {
957+ ) -> io:: Result < ( Vec < String > , Vec < String > , Vec < String > , bool ) > {
956958 let mut ret = Vec :: new ( ) ;
957959 let mut krates = Vec :: new ( ) ;
958960 let mut variables = Vec :: new ( ) ;
961+ let mut is_minified = false ;
959962
960963 if path. exists ( ) {
961964 for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
@@ -964,10 +967,11 @@ themePicker.onblur = handleThemeButtonsBlur;
964967 variables. push ( line. clone ( ) ) ;
965968 continue ;
966969 }
967- if !line. starts_with ( key) {
970+ if !line. starts_with ( key) || line . starts_with ( & format ! ( r#"{}["{}"]"# , key , krate ) ) {
968971 continue ;
969972 }
970- if line. starts_with ( & format ! ( r#"{}["{}"]"# , key, krate) ) {
973+ if line. starts_with ( MINIFIED_VARIABLES ) {
974+ is_minified = true ;
971975 continue ;
972976 }
973977 ret. push ( line. to_string ( ) ) ;
@@ -977,7 +981,7 @@ themePicker.onblur = handleThemeButtonsBlur;
977981 . unwrap_or_else ( || String :: new ( ) ) ) ;
978982 }
979983 }
980- Ok ( ( ret, krates, variables) )
984+ Ok ( ( ret, krates, variables, is_minified ) )
981985 }
982986
983987 fn show_item ( item : & IndexItem , krate : & str ) -> String {
@@ -992,7 +996,8 @@ themePicker.onblur = handleThemeButtonsBlur;
992996
993997 let dst = cx. dst . join ( & format ! ( "aliases{}.js" , cx. shared. resource_suffix) ) ;
994998 {
995- let ( mut all_aliases, _, _) = try_err ! ( collect( & dst, & krate. name, "ALIASES" , false ) , & dst) ;
999+ let ( mut all_aliases, _, _, _) = try_err ! ( collect( & dst, & krate. name, "ALIASES" , false ) ,
1000+ & dst) ;
9961001 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
9971002 let mut output = String :: with_capacity ( 100 ) ;
9981003 for ( alias, items) in & cache. aliases {
@@ -1088,33 +1093,37 @@ themePicker.onblur = handleThemeButtonsBlur;
10881093 }
10891094
10901095 let dst = cx. dst . join ( & format ! ( "source-files{}.js" , cx. shared. resource_suffix) ) ;
1091- let ( mut all_sources, _krates, _) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ,
1092- false ) ,
1093- & dst) ;
1096+ let ( mut all_sources, _krates, _, _ ) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ,
1097+ false ) ,
1098+ & dst) ;
10941099 all_sources. push ( format ! ( "sourcesIndex[\" {}\" ] = {};" ,
10951100 & krate. name,
10961101 hierarchy. to_json_string( ) ) ) ;
10971102 all_sources. sort ( ) ;
10981103 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
10991104 try_err ! ( writeln!( & mut w,
1100- "var N = null;var sourcesIndex = {{}};\n {}\n createSourceSidebar();" ,
1105+ "var N= null, sourcesIndex= {{}};\n {}\n createSourceSidebar();" ,
11011106 all_sources. join( "\n " ) ) ,
11021107 & dst) ;
11031108 }
11041109
11051110 // Update the search index
11061111 let dst = cx. dst . join ( & format ! ( "search-index{}.js" , cx. shared. resource_suffix) ) ;
1107- let ( mut all_indexes, mut krates, variables) = try_err ! ( collect( & dst,
1108- & krate. name,
1109- "searchIndex" ,
1110- true ) , & dst) ;
1112+ let ( mut all_indexes, mut krates, variables, is_minified ) = try_err ! ( collect( & dst,
1113+ & krate. name,
1114+ "searchIndex" ,
1115+ true ) , & dst) ;
11111116 all_indexes. push ( search_index) ;
11121117
11131118 // Sort the indexes by crate so the file will be generated identically even
11141119 // with rustdoc running in parallel.
11151120 all_indexes. sort ( ) ;
11161121 let mut w = try_err ! ( File :: create( & dst) , & dst) ;
1117- try_err ! ( writeln!( & mut w, "var N=null,E=\" \" ,T=\" t\" ,U=\" u\" ,searchIndex={{}};" ) , & dst) ;
1122+ if is_minified || options. enable_minification {
1123+ try_err ! ( writeln!( & mut w, "{}" , MINIFIED_VARIABLES ) , & dst) ;
1124+ } else {
1125+ try_err ! ( writeln!( & mut w, "var searchIndex={{}};" ) , & dst) ;
1126+ }
11181127 try_err ! ( write_minify_replacer( & mut w,
11191128 & format!( "{}\n {}" , variables. join( "" ) , all_indexes. join( "\n " ) ) ,
11201129 options. enable_minification) ,
@@ -1219,9 +1228,9 @@ themePicker.onblur = handleThemeButtonsBlur;
12191228 remote_item_type. css_class( ) ,
12201229 remote_path[ remote_path. len( ) - 1 ] ) ) ;
12211230
1222- let ( mut all_implementors, _, _) = try_err ! ( collect( & mydst, & krate. name, "implementors" ,
1223- false ) ,
1224- & mydst) ;
1231+ let ( mut all_implementors, _, _, _ ) = try_err ! ( collect( & mydst, & krate. name, "implementors" ,
1232+ false ) ,
1233+ & mydst) ;
12251234 all_implementors. push ( implementors) ;
12261235 // Sort the implementors by crate so the file will be generated
12271236 // identically even with rustdoc running in parallel.
0 commit comments