diff --git a/settings.html b/settings.html
index 9376159b4..f68cc5b0b 100644
--- a/settings.html
+++ b/settings.html
@@ -1,4 +1,4 @@
-
Rustdoc settings Rustdoc settings Theme preferences
Preferred dark theme
light dark ayu Preferred light theme
light dark ayu
-
+Rustdoc settings Rustdoc settings Theme preferences
Preferred dark theme
light dark ayu Preferred light theme
light dark ayu
+
\ No newline at end of file
diff --git a/src/uu_head/head.rs.html b/src/uu_head/head.rs.html
index bb215b103..31d680eb1 100644
--- a/src/uu_head/head.rs.html
+++ b/src/uu_head/head.rs.html
@@ -590,21 +590,6 @@
590
591
592
-593
-594
-595
-596
-597
-598
-599
-600
-601
-602
-603
-604
-605
-606
-607
@@ -716,6 +701,12 @@
Bytes (usize ),
}
+impl Default for Modes {
+ fn default () - > Self {
+ Modes::Lines (10 )
+ }
+}
+
fn parse_mode < F > (src : & str , closure : F ) - > Result < (Modes , bool ), String >
where
F : FnOnce (usize ) - > Modes ,
@@ -752,7 +743,7 @@
}
}
-#[derive (Debug , PartialEq )]
+#[derive (Debug , PartialEq , Default )]
struct HeadOptions {
pub quiet : bool ,
pub verbose : bool ,
@@ -763,22 +754,11 @@
}
impl HeadOptions {
- pub fn new () - > HeadOptions {
- HeadOptions {
- quiet : false ,
- verbose : false ,
- zeroed : false ,
- all_but_last : false ,
- mode : Modes::Lines (10 ),
- files : Vec::new (),
- }
- }
-
pub fn get_from (args : impl uucore::Args ) - > Result < Self , String > {
let matches = uu_app ().get_matches_from (arg_iterate (args )? );
- let mut options = HeadOptions::new ();
+ let mut options : HeadOptions = Default::default ();
options .quiet = matches .is_present (options::QUIET_NAME );
options .verbose = matches .is_present (options::VERBOSE_NAME );
@@ -805,12 +785,6 @@
Ok (options )
}
}
-
-impl Default for HeadOptions {
- fn default () - > Self {
- Self ::new ()
- }
-}
fn read_n_bytes < R > (input : R , n : usize ) - > std::io::Result < ()>
where
@@ -1131,17 +1105,13 @@
assert! (options ("-c IsThisJustFantasy" ).is_err ());
}
#[test ]
- #[allow (clippy::bool_comparison )]
fn test_options_correct_defaults () {
- let opts = HeadOptions::new ();
- let opts2 : HeadOptions = Default::default ();
+ let opts : HeadOptions = Default::default ();
- assert_eq! (opts , opts2 );
-
- assert! (opts .verbose = = false );
- assert! (opts .quiet = = false );
- assert! (opts .zeroed = = false );
- assert! (opts .all_but_last = = false );
+ assert! (! opts .verbose );
+ assert! (! opts .quiet );
+ assert! (! opts .zeroed );
+ assert! (! opts .all_but_last );
assert_eq! (opts .mode , Modes::Lines (10 ));
assert! (opts .files .is_empty ());
}
diff --git a/src/uu_tac/tac.rs.html b/src/uu_tac/tac.rs.html
index d75352b83..2ce722bc2 100644
--- a/src/uu_tac/tac.rs.html
+++ b/src/uu_tac/tac.rs.html
@@ -254,6 +254,51 @@
254
255
256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
@@ -262,15 +307,19 @@
-
+
#[macro_use ]
extern crate uucore ;
use clap ::{crate_version , App , Arg };
use memchr::memmem ;
-use std::io ::{stdin , stdout , BufReader , Read , Write };
-use std ::{fs::File , path::Path };
+use memmap2::Mmap ;
+use std::io ::{stdin , stdout , BufWriter , Read , Write };
+use std ::{
+ fs ::{read , File },
+ path::Path ,
+};
use uucore::display::Quotable ;
use uucore::InvalidEncodingHandling ;
@@ -301,9 +350,9 @@
raw_separator
};
- let files : Vec < String > = match matches .values_of (options::FILE ) {
- Some (v ) = > v .map (| v | v .to_owned ()).collect (),
- None = > vec! ["-" .to_owned ()],
+ let files : Vec < & str > = match matches .values_of (options::FILE ) {
+ Some (v ) = > v .collect (),
+ None = > vec! ["-" ],
};
tac (files , before , regex , separator )
@@ -359,10 +408,11 @@
fn buffer_tac_regex (
data : & [u8 ],
- pattern : regex::bytes::Regex ,
+ pattern : & regex::bytes::Regex ,
before : bool ,
) - > std::io::Result < ()> {
- let mut out = stdout ();
+ let out = stdout ();
+ let mut out = BufWriter::new (out .lock ());
@@ -428,7 +478,8 @@
fn buffer_tac (data : & [u8 ], before : bool , separator : & str ) - > std::io::Result < ()> {
- let mut out = stdout ();
+ let out = stdout ();
+ let mut out = BufWriter::new (out .lock ());
let slen = separator .as_bytes ().len ();
@@ -465,12 +516,33 @@
Ok (())
}
-fn tac (filenames : Vec < String > , before : bool , regex : bool , separator : & str ) - > i32 {
+fn tac (filenames : Vec < & str > , before : bool , regex : bool , separator : & str ) - > i32 {
let mut exit_code = 0 ;
- for filename in & filenames {
- let mut file = BufReader::new (if filename = = "-" {
- Box::new (stdin ()) as Box < dyn Read >
+ let pattern = if regex {
+ Some (crash_if_err! (1 , regex::bytes::Regex::new (separator )))
+ } else {
+ None
+ };
+
+ for & filename in & filenames {
+ let mmap ;
+ let buf ;
+
+ let data : & [u8 ] = if filename = = "-" {
+ if let Some (mmap1 ) = try_mmap_stdin () {
+ mmap = mmap1 ;
+ & mmap
+ } else {
+ let mut buf1 = Vec::new ();
+ if let Err (e ) = stdin ().read_to_end (& mut buf1 ) {
+ show_error! ("failed to read from stdin: {}" , e );
+ exit_code = 1 ;
+ continue ;
+ }
+ buf = buf1 ;
+ & buf
+ }
} else {
let path = Path::new (filename );
if path .is_dir () | | path .metadata ().is_err () {
@@ -485,32 +557,50 @@
exit_code = 1 ;
continue ;
}
- match File::open (path ) {
- Ok (f ) = > Box::new (f ) as Box < dyn Read > ,
- Err (e ) = > {
- show_error! ("failed to open {} for reading: {}" , filename .quote (), e );
- exit_code = 1 ;
- continue ;
+
+ if let Some (mmap1 ) = try_mmap_path (path ) {
+ mmap = mmap1 ;
+ & mmap
+ } else {
+ match read (path ) {
+ Ok (buf1 ) = > {
+ buf = buf1 ;
+ & buf
+ }
+ Err (e ) = > {
+ show_error! ("failed to read {}: {}" , filename .quote (), e );
+ exit_code = 1 ;
+ continue ;
+ }
}
}
- });
-
- let mut data = Vec::new ();
- if let Err (e ) = file .read_to_end (& mut data ) {
- show_error! ("failed to read {}: {}" , filename .quote (), e );
- exit_code = 1 ;
- continue ;
};
- if regex {
- let pattern = crash_if_err! (1 , regex::bytes::Regex::new (separator ));
- buffer_tac_regex (& data , pattern , before )
+
+ if let Some (pattern ) = & pattern {
+ buffer_tac_regex (data , pattern , before )
} else {
- buffer_tac (& data , before , separator )
+ buffer_tac (data , before , separator )
}
.unwrap_or_else (| e | crash! (1 , "failed to write to stdout: {}" , e ));
}
exit_code
}
+
+fn try_mmap_stdin () - > Option < Mmap > {
+
+
+ unsafe { Mmap::map (& stdin ()).ok () }
+}
+
+fn try_mmap_path (path : & Path ) - > Option < Mmap > {
+ let file = File::open (path ).ok ()? ;
+
+
+
+ let mmap = unsafe { Mmap::map (& file ).ok ()? };
+
+ Some (mmap )
+}
diff --git a/uu_head/fn.uumain.html b/uu_head/fn.uumain.html
index 3656601ab..5f0c58034 100644
--- a/uu_head/fn.uumain.html
+++ b/uu_head/fn.uumain.html
@@ -1,3 +1,3 @@
-uumain in uu_head - Rust pub fn uumain(args: impl Args ) -> i32
+uumain in uu_head - Rust pub fn uumain(args: impl Args ) -> i32
\ No newline at end of file
diff --git a/uu_head/index.html b/uu_head/index.html
index 63041dffc..39b40cb96 100644
--- a/uu_head/index.html
+++ b/uu_head/index.html
@@ -1,4 +1,4 @@
-uu_head - Rust
+uu_head - Rust
\ No newline at end of file
diff --git a/uu_tac/fn.uu_app.html b/uu_tac/fn.uu_app.html
index 02f82dbee..89697bbb3 100644
--- a/uu_tac/fn.uu_app.html
+++ b/uu_tac/fn.uu_app.html
@@ -1,3 +1,3 @@
-uu_app in uu_tac - Rust pub fn uu_app() -> App <'static, 'static>
+uu_app in uu_tac - Rust pub fn uu_app() -> App <'static, 'static>
\ No newline at end of file
diff --git a/uu_tac/fn.uumain.html b/uu_tac/fn.uumain.html
index 74f91dac9..869164b64 100644
--- a/uu_tac/fn.uumain.html
+++ b/uu_tac/fn.uumain.html
@@ -1,3 +1,3 @@
-uumain in uu_tac - Rust pub fn uumain(args: impl Args ) -> i32
+uumain in uu_tac - Rust pub fn uumain(args: impl Args ) -> i32
\ No newline at end of file
diff --git a/uu_tac/index.html b/uu_tac/index.html
index ed732f2c9..5f9370b60 100644
--- a/uu_tac/index.html
+++ b/uu_tac/index.html
@@ -1,4 +1,4 @@
-uu_tac - Rust
+uu_tac - Rust
\ No newline at end of file