@@ -496,17 +496,20 @@ fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
496496 print_unbuffered ( handle, stdout)
497497}
498498
499+ // print without io::stdout's buffering
499500#[ cfg_attr( any( target_os = "linux" , target_os = "android" ) , inline( never) ) ] // splice fast-path does not require this allocation
500501#[ cfg( any( unix, target_os = "wasi" ) ) ]
501502fn print_unbuffered < R : FdReadable > (
502503 handle : & mut InputHandle < R > ,
503504 stdout : io:: Stdout ,
504505) -> CatResult < ( ) > {
505- // todo: since there is no cost by 0-fill, we could use larger heap buffer for throughput
506- let mut buf = [ std:: mem:: MaybeUninit :: < u8 > :: uninit ( ) ; 1024 * 64 ] ;
507- // use raw syscall to remove buffering
506+ // since there is no cost by 0-fill, we use larger buffer for throughput
507+ // this size is still useful if splice failed, but fcntl succeed
508+ const MAX_ROOTLESS_PIPE_SIZE : usize = 1024 * 1024 ;
509+ let mut buf = Vec :: with_capacity ( MAX_ROOTLESS_PIPE_SIZE ) ;
510+ let buf = buf. spare_capacity_mut ( ) ;
508511 loop {
509- match rustix:: io:: read ( & handle. reader , & mut buf) {
512+ match rustix:: io:: read ( & handle. reader , & mut * buf) {
510513 Ok ( ( [ ] , _) ) => return Ok ( ( ) ) ,
511514 Ok ( ( filled, _) ) => {
512515 uucore:: io:: write_all_raw ( & stdout, filled) . inspect_err ( handle_broken_pipe) ?;
0 commit comments