From: Pádraig Brady Date: Tue, 24 Mar 2026 18:53:03 +0000 (+0000) Subject: cut: enable fast path for all delimiter lengths X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1da3ccced20b130a89f2df082b7205e0b6694638;p=thirdparty%2Fcoreutils.git cut: enable fast path for all delimiter lengths 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 --- diff --git a/src/cut.c b/src/cut.c index e3e8d49923..8b7489238b 100644 --- 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;