@@ -167,23 +167,24 @@ pub(super) fn write_shared(
167167 let mut krates = Vec :: new ( ) ;
168168
169169 if path. exists ( ) {
170- let prefix = format ! ( "\" {krate}\" " ) ;
170+ let prefix = format ! ( "[ \" {krate}\" " ) ;
171171 for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
172172 let line = line?;
173- if !line. starts_with ( '"' ) {
173+ if !line. starts_with ( "[ \" " ) {
174174 continue ;
175175 }
176176 if line. starts_with ( & prefix) {
177177 continue ;
178178 }
179- if line. ends_with ( ",\\ " ) {
179+ if line. ends_with ( "] ,\\ " ) {
180180 ret. push ( line[ ..line. len ( ) - 2 ] . to_string ( ) ) ;
181181 } else {
182182 // Ends with "\\" (it's the case for the last added crate line)
183183 ret. push ( line[ ..line. len ( ) - 1 ] . to_string ( ) ) ;
184184 }
185185 krates. push (
186- line. split ( '"' )
186+ line[ 1 ..] // We skip the `[` parent at the beginning of the line.
187+ . split ( '"' )
187188 . find ( |s| !s. is_empty ( ) )
188189 . map ( |s| s. to_owned ( ) )
189190 . unwrap_or_else ( String :: new) ,
@@ -285,7 +286,7 @@ pub(super) fn write_shared(
285286 let ( mut all_sources, _krates) =
286287 try_err ! ( collect_json( & dst, krate. name( cx. tcx( ) ) . as_str( ) ) , & dst) ;
287288 all_sources. push ( format ! (
288- r#""{}":{} "# ,
289+ r#"[ "{}",{}] "# ,
289290 & krate. name( cx. tcx( ) ) ,
290291 hierarchy
291292 . to_json_string( )
@@ -296,9 +297,9 @@ pub(super) fn write_shared(
296297 . replace( "\\ \" " , "\\ \\ \" " )
297298 ) ) ;
298299 all_sources. sort ( ) ;
299- let mut v = String :: from ( "var srcIndex = JSON.parse('{ \\ \n " ) ;
300+ let mut v = String :: from ( "const srcIndex = new Map( JSON.parse('[ \\ \n " ) ;
300301 v. push_str ( & all_sources. join ( ",\\ \n " ) ) ;
301- v. push_str ( "\\ \n }' );\n createSrcSidebar();\n " ) ;
302+ v. push_str ( "\\ \n ]') );\n createSrcSidebar();\n " ) ;
302303 Ok ( v. into_bytes ( ) )
303304 } ;
304305 write_invocation_specific ( "src-files.js" , & make_sources) ?;
@@ -316,11 +317,11 @@ pub(super) fn write_shared(
316317 // with rustdoc running in parallel.
317318 all_indexes. sort ( ) ;
318319 write_invocation_specific ( "search-index.js" , & || {
319- let mut v = String :: from ( "var searchIndex = JSON.parse('{ \\ \n " ) ;
320+ let mut v = String :: from ( "const searchIndex = new Map( JSON.parse('[ \\ \n " ) ;
320321 v. push_str ( & all_indexes. join ( ",\\ \n " ) ) ;
321322 v. push_str (
322323 r#"\
323- }' );
324+ ]') );
324325if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)};
325326if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
326327"# ,
0 commit comments