@@ -1257,7 +1257,6 @@ impl Context {
1257
1257
1258
1258
info ! ( "Recursing into {}" , self . dst. display( ) ) ;
1259
1259
1260
- mkdir ( & self . dst ) . unwrap ( ) ;
1261
1260
let ret = f ( self ) ;
1262
1261
1263
1262
info ! ( "Recursed; leaving {}" , self . dst. display( ) ) ;
@@ -1301,7 +1300,7 @@ impl Context {
1301
1300
fn item < F > ( & mut self , item : clean:: Item , mut f : F ) -> Result < ( ) , Error > where
1302
1301
F : FnMut ( & mut Context , clean:: Item ) ,
1303
1302
{
1304
- fn render ( w : File , cx : & Context , it : & clean:: Item ,
1303
+ fn render ( writer : & mut io :: Write , cx : & Context , it : & clean:: Item ,
1305
1304
pushname : bool ) -> io:: Result < ( ) > {
1306
1305
// A little unfortunate that this is done like this, but it sure
1307
1306
// does make formatting *a lot* nicer.
@@ -1336,12 +1335,8 @@ impl Context {
1336
1335
1337
1336
reset_ids ( true ) ;
1338
1337
1339
- // We have a huge number of calls to write, so try to alleviate some
1340
- // of the pain by using a buffered writer instead of invoking the
1341
- // write syscall all the time.
1342
- let mut writer = BufWriter :: new ( w) ;
1343
1338
if !cx. render_redirect_pages {
1344
- layout:: render ( & mut writer, & cx. shared . layout , & page,
1339
+ layout:: render ( writer, & cx. shared . layout , & page,
1345
1340
& Sidebar { cx : cx, item : it } ,
1346
1341
& Item { cx : cx, item : it } ,
1347
1342
cx. shared . css_file_extension . is_some ( ) ) ?;
@@ -1354,10 +1349,10 @@ impl Context {
1354
1349
url. push_str ( "/" ) ;
1355
1350
}
1356
1351
url. push_str ( & item_path ( it) ) ;
1357
- layout:: redirect ( & mut writer, & url) ?;
1352
+ layout:: redirect ( writer, & url) ?;
1358
1353
}
1359
1354
}
1360
- writer . flush ( )
1355
+ Ok ( ( ) )
1361
1356
}
1362
1357
1363
1358
// Stripped modules survive the rustdoc passes (i.e. `strip-private`)
@@ -1378,9 +1373,16 @@ impl Context {
1378
1373
let mut item = Some ( item) ;
1379
1374
self . recurse ( name, |this| {
1380
1375
let item = item. take ( ) . unwrap ( ) ;
1381
- let joint_dst = this. dst . join ( "index.html" ) ;
1382
- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1383
- try_err ! ( render( dst, this, & item, false ) , & joint_dst) ;
1376
+
1377
+ let mut buf = Vec :: new ( ) ;
1378
+ render ( & mut buf, this, & item, false ) . unwrap ( ) ;
1379
+ // buf will be empty if the module is stripped and there is no redirect for it
1380
+ if !buf. is_empty ( ) {
1381
+ let joint_dst = this. dst . join ( "index.html" ) ;
1382
+ try_err ! ( fs:: create_dir_all( & this. dst) , & this. dst) ;
1383
+ let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1384
+ try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1385
+ }
1384
1386
1385
1387
let m = match item. inner {
1386
1388
clean:: StrippedItem ( box clean:: ModuleItem ( m) ) |
@@ -1389,7 +1391,7 @@ impl Context {
1389
1391
} ;
1390
1392
1391
1393
// render sidebar-items.js used throughout this module
1392
- {
1394
+ if !this . render_redirect_pages {
1393
1395
let items = this. build_sidebar_items ( & m) ;
1394
1396
let js_dst = this. dst . join ( "sidebar-items.js" ) ;
1395
1397
let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
@@ -1403,10 +1405,15 @@ impl Context {
1403
1405
Ok ( ( ) )
1404
1406
} )
1405
1407
} else if item. name . is_some ( ) {
1406
- let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1407
-
1408
- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1409
- try_err ! ( render( dst, self , & item, true ) , & joint_dst) ;
1408
+ let mut buf = Vec :: new ( ) ;
1409
+ render ( & mut buf, self , & item, true ) . unwrap ( ) ;
1410
+ // buf will be empty if the item is stripped and there is no redirect for it
1411
+ if !buf. is_empty ( ) {
1412
+ let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1413
+ try_err ! ( fs:: create_dir_all( & self . dst) , & self . dst) ;
1414
+ let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1415
+ try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1416
+ }
1410
1417
Ok ( ( ) )
1411
1418
} else {
1412
1419
Ok ( ( ) )
0 commit comments