Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

head: fix bug with non-terminated files. #7484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

karlmcdowall
Copy link
Contributor

@karlmcdowall karlmcdowall commented Mar 18, 2025

Fixes #7472.
Update to head app when printing all-but-last-n-lines of a file.
Code now checks if the last line of the input file is missing a terminating newline character, and if so prints an extra line in the output. This aligns with GNU-head behavior.

Also made a change to improve performance of this usecase by using an optimized iterator (memchr-iter) for searching through the input file (gives a ~25% improvement for head -n -100000 ./shakespeare.txt vs the current mainline tip).

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@karlmcdowall karlmcdowall marked this pull request as ready for review March 18, 2025 20:17
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

Fixes issue uutils#7472.
Update to head app when printing all-but-last-n-lines of a file.
Code now checks if the last line of the input file is missing a terminating
newline character, and if so prints an extra line.
This aligns with GNU-head behavior.
Also improved performance of this usecase by using an optimized iterator
(memchr-iter) for searching through the input file.
Copy link

GNU testsuite comparison:

Congrats! The gnu test misc/stdbuf.log is no longer failing!
Congrats! The gnu test timeout/timeout.log is no longer failing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

head: printing all-but-last-n-lines discrepancy with GNU
2 participants