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
This commit is contained in:
Pádraig Brady committed 2026-04-05 13:15:56 +01:00
1 parent 7a124eb585
commit 1da3ccced2
1 file changed
+8 -2
+8 -2
View File
@@ -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;