From 2b2c2b64c26487387b4f536f7ed78babc30add23 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sun, 27 Mar 2016 14:29:47 -0700 Subject: [PATCH] tail: When tailing a file in bytes mode, seek directly to the specified byte When tailing a file, as opposed to stdin, and we are tailing bytes rather than lines, we can seek the requested number of bytes from the end of the file. This side steps the whole `backwards_thru_file` file loop and blocks of reads. Fixes #833. --- src/tail/tail.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tail/tail.rs b/src/tail/tail.rs index 996740e81..865f4f40c 100755 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -336,11 +336,8 @@ fn bounded_tail(mut file: File, settings: &Settings) { } }); }, - FilterMode::Bytes(mut count) => { - backwards_thru_file(&mut file, size, &mut buf, &mut |_| { - count -= 1; - count == 0 - }); + FilterMode::Bytes(count) => { + file.seek(SeekFrom::End(-(count as i64))).unwrap(); }, }