File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,15 @@ fn expand_line(
358358) -> std:: io:: Result < ( ) > {
359359 use self :: CharType :: { Backspace , Other , Tab } ;
360360
361+ // Fast path: if there are no tabs, backspaces, and (in UTF-8 mode or no carriage returns),
362+ // we can write the buffer directly without character-by-character processing
363+ if !buf. contains ( & b'\t' ) && !buf. contains ( & b'\x08' ) && ( options. uflag || !buf. contains ( & b'\r' ) )
364+ {
365+ output. write_all ( buf) ?;
366+ buf. truncate ( 0 ) ;
367+ return Ok ( ( ) ) ;
368+ }
369+
361370 let mut col = 0 ;
362371 let mut byte = 0 ;
363372 let mut init = true ;
@@ -435,7 +444,6 @@ fn expand_line(
435444 byte += nbytes; // advance the pointer
436445 }
437446
438- output. flush ( ) ?;
439447 buf. truncate ( 0 ) ; // clear the buffer
440448
441449 Ok ( ( ) )
@@ -471,6 +479,10 @@ fn expand(options: &Options) -> UResult<()> {
471479 }
472480 }
473481 }
482+ // Flush once at the end
483+ output
484+ . flush ( )
485+ . map_err_context ( || translate ! ( "expand-error-failed-to-write-output" ) ) ?;
474486 Ok ( ( ) )
475487}
476488
You can’t perform that action at this time.
0 commit comments