]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cut: enable fast path for all delimiter lengths
authorPádraig Brady <P@draigBrady.com>
Tue, 24 Mar 2026 18:53:03 +0000 (18:53 +0000)
committerPádraig Brady <P@draigBrady.com>
Sun, 5 Apr 2026 12:15:56 +0000 (13:15 +0100)
1. Removed !have_pending_line from the fast path condition.
This is safe because:
  - field_1_n_bytes == 0 already ensures we haven't started
    buffering field 1 content
  - The fast path correctly continues any pending partial line
    by writing raw bytes including the completing \n
2. Added have_pending_line = false after the fast path write,
since all lines up to the last \n are now complete.

$ time src/cut.before -f1 -dç sl.in >/dev/null
real 0m0.081s
$ time src/cut.after -f1 -dç sl.in >/dev/null
real 0m0.012s

$ time src/cut.before -f10 -dç sl.in >/dev/null
real 0m0.081s
$ time src/cut.after -f10 -dç sl.in >/dev/null
real 0m0.012s

src/cut.c

index e3e8d49923c70e12d2ab5459a8c0eab38a4fb1f5..8b7489238b2bbebcd65eb97d1d128dcc2ce8498c 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -1050,8 +1050,6 @@ cut_fields_bytesearch (FILE *stream)
       if (field_idx == 1
           && !suppress_non_delimited && !whitespace_delimited
           && !field_delim_is_line_delim ()
-          && !have_pending_line
-          && field_1_n_bytes == 0
           && !skip_line_remainder
           && !find_bytesearch_field_delim (chunk, safe))
         {
@@ -1059,11 +1057,19 @@ cut_fields_bytesearch (FILE *stream)
                                   : memrchr ((void *) chunk, line_delim, safe);
           if (last_line_delim)
             {
+              /* Flush any buffered field 1 data from a prior
+                 partial chunk that had no delimiter.  */
+              if (field_1_n_bytes > 0)
+                {
+                  write_bytes (field_1_buffer, field_1_n_bytes);
+                  field_1_n_bytes = 0;
+                }
               idx_t n = last_line_delim - chunk + 1;
               write_bytes (chunk, n);
               if (feof (mbbuf.fp) && chunk[n - 1] != line_delim)
                 write_line_delim ();
               mbbuf_advance (&mbbuf, n);
+              have_pending_line = false;
               if (feof (mbbuf.fp))
                 return;
               continue;