@@ -32,7 +32,7 @@ use libc::S_IFIFO;
32
32
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
33
33
use uucore:: pipes:: { pipe, splice, splice_exact} ;
34
34
35
- const BUF_SIZE : usize = 16 * 1024 ;
35
+ const BUF_SIZE : usize = 256 * 1024 ;
36
36
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
37
37
const SPLICE_SIZE : usize = 128 * 1024 ;
38
38
@@ -197,6 +197,23 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
197
197
}
198
198
}
199
199
200
+ /// A simple structure used to align a BUF_SIZE buffer to 32-byte boundary.
201
+ ///
202
+ /// This is useful as bytecount uses 256-bit wide vector operations that run much
203
+ /// faster on aligned data (at least on x86 with AVX2 support).
204
+ #[ repr( align( 32 ) ) ]
205
+ struct AlignedBuffer {
206
+ data : [ u8 ; BUF_SIZE ] ,
207
+ }
208
+
209
+ impl Default for AlignedBuffer {
210
+ fn default ( ) -> Self {
211
+ Self {
212
+ data : [ 0 ; BUF_SIZE ] ,
213
+ }
214
+ }
215
+ }
216
+
200
217
/// Returns a WordCount that counts the number of bytes, lines, and/or the number of Unicode characters encoded in UTF-8 read via a Reader.
201
218
///
202
219
/// This corresponds to the `-c`, `-l` and `-m` command line flags to wc.
@@ -213,9 +230,9 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
213
230
handle : & mut R ,
214
231
) -> ( WordCount , Option < io:: Error > ) {
215
232
let mut total = WordCount :: default ( ) ;
216
- let mut buf = [ 0 ; BUF_SIZE ] ;
233
+ let buf : & mut [ u8 ] = & mut AlignedBuffer :: default ( ) . data ;
217
234
loop {
218
- match handle. read ( & mut buf) {
235
+ match handle. read ( buf) {
219
236
Ok ( 0 ) => return ( total, None ) ,
220
237
Ok ( n) => {
221
238
if COUNT_BYTES {
0 commit comments