@@ -32,7 +32,7 @@ use libc::S_IFIFO;
3232#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
3333use uucore:: pipes:: { pipe, splice, splice_exact} ;
3434
35- const BUF_SIZE : usize = 16 * 1024 ;
35+ const BUF_SIZE : usize = 256 * 1024 ;
3636#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
3737const SPLICE_SIZE : usize = 128 * 1024 ;
3838
@@ -197,6 +197,23 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
197197 }
198198}
199199
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+
200217/// 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.
201218///
202219/// 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<
213230 handle : & mut R ,
214231) -> ( WordCount , Option < io:: Error > ) {
215232 let mut total = WordCount :: default ( ) ;
216- let mut buf = [ 0 ; BUF_SIZE ] ;
233+ let buf : & mut [ u8 ] = & mut AlignedBuffer :: default ( ) . data ;
217234 loop {
218- match handle. read ( & mut buf) {
235+ match handle. read ( buf) {
219236 Ok ( 0 ) => return ( total, None ) ,
220237 Ok ( n) => {
221238 if COUNT_BYTES {
0 commit comments