@@ -262,6 +262,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
262
262
} ) ;
263
263
cache. stack . push ( krate. name . clone ( ) ) ;
264
264
krate = cache. fold_crate ( krate) ;
265
+
266
+ let mut nodeid_to_pathid = HashMap :: new ( ) ;
267
+ let mut pathid_to_nodeid = Vec :: new ( ) ;
265
268
{
266
269
let Cache { search_index : ref mut index,
267
270
orphan_methods : ref meths, paths : ref mut paths, ..} = cache;
@@ -283,17 +286,21 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
283
286
}
284
287
} ;
285
288
286
- // Prune the paths that do not appear in the index.
287
- let mut unseen : HashSet < ast :: NodeId > = paths. keys ( ) . map ( | & id| id ) . collect ( ) ;
289
+ // Reduce `NodeId` in paths into smaller sequential numbers,
290
+ // and prune the paths that do not appear in the index.
288
291
for item in index. iter ( ) {
289
292
match item. parent {
290
- Some ( ref pid) => { unseen. remove ( pid) ; }
293
+ Some ( nodeid) => {
294
+ if !nodeid_to_pathid. contains_key ( & nodeid) {
295
+ let pathid = pathid_to_nodeid. len ( ) ;
296
+ nodeid_to_pathid. insert ( nodeid, pathid) ;
297
+ pathid_to_nodeid. push ( nodeid) ;
298
+ }
299
+ }
291
300
None => { }
292
301
}
293
302
}
294
- for pid in unseen. iter ( ) {
295
- paths. remove ( pid) ;
296
- }
303
+ assert_eq ! ( nodeid_to_pathid. len( ) , pathid_to_nodeid. len( ) ) ;
297
304
}
298
305
299
306
// Publish the search index
@@ -308,23 +315,25 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
308
315
item. ty, item. name, item. path,
309
316
item. desc. to_json( ) . to_str( ) ) ) ;
310
317
match item. parent {
311
- Some ( id) => {
312
- try!( write ! ( & mut w, ",parent:'{}'" , id) ) ;
318
+ Some ( nodeid) => {
319
+ let pathid = * nodeid_to_pathid. find ( & nodeid) . unwrap ( ) ;
320
+ try!( write ! ( & mut w, ",parent:{}" , pathid) ) ;
313
321
}
314
322
None => { }
315
323
}
316
324
try!( write ! ( & mut w, "\\ }" ) ) ;
317
325
}
318
326
try!( write ! ( & mut w, "];" ) ) ;
319
- try!( write ! ( & mut w, "allPaths['{}'] = \\ {" , krate. name) ) ;
320
- for ( i, ( & id, & ( ref fqp, short) ) ) in cache. paths . iter ( ) . enumerate ( ) {
327
+ try!( write ! ( & mut w, "allPaths['{}'] = [" , krate. name) ) ;
328
+ for ( i, & nodeid) in pathid_to_nodeid. iter ( ) . enumerate ( ) {
329
+ let & ( ref fqp, short) = cache. paths . find ( & nodeid) . unwrap ( ) ;
321
330
if i > 0 {
322
331
try!( write ! ( & mut w, "," ) ) ;
323
332
}
324
- try!( write ! ( & mut w, "'{}': \\ {type:'{}',name:'{}'\\ }" ,
325
- id , short, * fqp. last( ) . unwrap( ) ) ) ;
333
+ try!( write ! ( & mut w, "\\ {type:'{}',name:'{}'\\ }" ,
334
+ short, * fqp. last( ) . unwrap( ) ) ) ;
326
335
}
327
- try!( write ! ( & mut w, "\\ } ;" ) ) ;
336
+ try!( write ! ( & mut w, "] ;" ) ) ;
328
337
329
338
str:: from_utf8 ( w. unwrap ( ) . as_slice ( ) ) . unwrap ( ) . to_owned ( )
330
339
} ;
0 commit comments