Increases throughput when no delimiters found by up to 15x.

  $ yes | head -n10M > sl.in

  $ time LC_ALL=C src/cut-before -f10 -w sl.in >/dev/null
  real  0m0.171s

  $ time LC_ALL=C src/cut-after -f10 -w sl.in >/dev/null
  real  0m0.011s

* src/cut.c (cut_fields_bytesearch): Also add a byte search
shortcut for the -w case in uni-byte locales.
---
 src/cut.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index aa38e72c9..4d2bf9390 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -1166,9 +1166,11 @@ cut_fields_bytesearch (FILE *stream)
 
       /* Fast path: no field delimiter in chunk — output or skip lines.  */
       if (field_idx == 1
-          && !whitespace_delimited
+          && (!whitespace_delimited || !field_selection_exhausted (field_idx))
           && !field_delim_is_line_delim ()
-          && !find_field_delim (chunk, n_avail))
+          && !(whitespace_delimited
+               ? find_c_blank (chunk, n_avail)
+               : find_field_delim (chunk, n_avail)))
         {
           char *last_line_delim = search.at_eof
                                   ? chunk + n_avail - 1
-- 
2.55.0


Reply via email to