@@ -932,7 +932,7 @@ impl<'a, W: Write> Write for LineWriterShim<'a, W> {
932
932
} ;
933
933
Ok ( flushed + buffered)
934
934
}
935
- } ;
935
+ }
936
936
}
937
937
938
938
fn flush ( & mut self ) -> io:: Result < ( ) > {
@@ -1027,35 +1027,37 @@ impl<'a, W: Write> Write for LineWriterShim<'a, W> {
1027
1027
/// writer, it will also flush the existing buffer if it contains any
1028
1028
/// newlines, even if the incoming data does not contain any newlines.
1029
1029
fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
1030
- // If there are no new newlines (that is, if this write is less than
1031
- // one line), just do a regular buffered write
1032
- let newline_idx = match memchr :: memrchr ( b'\n' , buf ) {
1030
+ match memchr :: memrchr ( b'\n' , buf ) {
1031
+ // If there are no new newlines (that is, if this write is less than
1032
+ // one line), just do a regular buffered write
1033
1033
None => {
1034
1034
// Check for prior partial line writes that need to be retried.
1035
1035
// Only retry if the buffer contains a completed line, to
1036
1036
// avoid flushing partial lines.
1037
1037
if let Some ( b'\n' ) = self . inner . buffer ( ) . last ( ) . copied ( ) {
1038
1038
self . inner . flush_buf ( ) ?;
1039
1039
}
1040
- return self . inner . write_all ( buf) ;
1040
+ self . inner . write_all ( buf)
1041
1041
}
1042
- Some ( i ) => i ,
1043
- } ;
1044
-
1045
- // Flush existing content to prepare for our write
1046
- self . inner . flush_buf ( ) ?;
1042
+ // Otherwise, arrange for the lines to be written directly to the
1043
+ // inner writer.
1044
+ Some ( newline_idx ) => {
1045
+ // Flush existing content to prepare for our write
1046
+ self . inner . flush_buf ( ) ?;
1047
1047
1048
- // This is what we're going to try to write directly to the inner
1049
- // writer. The rest will be buffered, if nothing goes wrong.
1050
- let ( lines, tail) = buf. split_at ( newline_idx + 1 ) ;
1048
+ // This is what we're going to try to write directly to the inner
1049
+ // writer. The rest will be buffered, if nothing goes wrong.
1050
+ let ( lines, tail) = buf. split_at ( newline_idx + 1 ) ;
1051
1051
1052
- // Write `lines` directly to the inner writer, bypassing the buffer.
1053
- self . inner . get_mut ( ) . write_all ( lines) ?;
1052
+ // Write `lines` directly to the inner writer, bypassing the buffer.
1053
+ self . inner . get_mut ( ) . write_all ( lines) ?;
1054
1054
1055
- // Now that the write has succeeded, buffer the rest with BufWriter::write_all.
1056
- // This will buffer as much as possible, but continue flushing as
1057
- // necessary if our tail is huge.
1058
- self . inner . write_all ( tail)
1055
+ // Now that the write has succeeded, buffer the rest with BufWriter::write_all.
1056
+ // This will buffer as much as possible, but continue flushing as
1057
+ // necessary if our tail is huge.
1058
+ self . inner . write_all ( tail)
1059
+ }
1060
+ }
1059
1061
}
1060
1062
}
1061
1063
0 commit comments