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