@@ -149,44 +149,36 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
149149 }
150150 }
151151 }
152+ // Else, if we're on Linux and our file is a FIFO pipe
153+ // (or stdin), we use splice to count the number of bytes.
152154 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
153- {
154- // Else, if we're on Linux and our file is a FIFO pipe
155- // (or stdin), we use splice to count the number of bytes.
156- if ( stat. st_mode as libc:: mode_t & S_IFIFO ) != 0 {
157- match count_bytes_using_splice ( handle) {
158- Ok ( n) => return ( n, None ) ,
159- Err ( n) => byte_count = n,
160- }
155+ if ( stat. st_mode as libc:: mode_t & S_IFIFO ) != 0 {
156+ match count_bytes_using_splice ( handle) {
157+ Ok ( n) => return ( n, None ) ,
158+ Err ( n) => byte_count = n,
161159 }
162160 }
163161 }
164162 }
165163
166164 #[ cfg( windows) ]
165+ if let Some ( file) = handle. inner_file ( )
166+ && let Ok ( metadata) = file. metadata ( )
167167 {
168- if let Some ( file) = handle. inner_file ( ) {
169- if let Ok ( metadata) = file. metadata ( ) {
170- let attributes = metadata. file_attributes ( ) ;
171-
172- if ( attributes & FILE_ATTRIBUTE_ARCHIVE ) != 0
173- || ( attributes & FILE_ATTRIBUTE_NORMAL ) != 0
174- {
175- return ( metadata. file_size ( ) as usize , None ) ;
176- }
177- }
168+ let attributes = metadata. file_attributes ( ) ;
169+ if ( attributes & FILE_ATTRIBUTE_ARCHIVE ) != 0 || ( attributes & FILE_ATTRIBUTE_NORMAL ) != 0 {
170+ return ( metadata. file_size ( ) as usize , None ) ;
178171 }
179172 }
180173
181174 // Fall back on `read`, but without the overhead of counting words and lines.
175+
182176 let mut buf = [ 0_u8 ; BUF_SIZE ] ;
183177 loop {
184178 match handle. read ( & mut buf) {
185179 Ok ( 0 ) => return ( byte_count, None ) ,
186- Ok ( n) => {
187- byte_count += n;
188- }
189- Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => ( ) ,
180+ Ok ( n) => byte_count += n,
181+ Err ( e) if e. kind ( ) == ErrorKind :: Interrupted => ( ) ,
190182 Err ( e) => return ( byte_count, Some ( e) ) ,
191183 }
192184 }
@@ -250,7 +242,7 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
250242 } ;
251243 }
252244 }
253- Err ( ref e) if e. kind ( ) == ErrorKind :: Interrupted => ( ) ,
245+ Err ( e) if e. kind ( ) == ErrorKind :: Interrupted => ( ) ,
254246 Err ( e) => return ( total, Some ( e) ) ,
255247 }
256248 }
0 commit comments