grep: short-circuit max-count zero#46
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
8fc34c5 to
bbf205f
Compare
lhecker
left a comment
There was a problem hiding this comment.
I believe this conflicts with your other PR. I suppose we should let the other one merge first.
|
Thanks, that makes sense. The overlap is the early-return slot after I agree #43 is the better one to land first if maintainers want that behavior in place before this one. I’ll keep this PR as-is since it is independently green and approved, then rebase it after #43 lands so the final code keeps both short-circuits together and preserves the current ordering: compile/validate the pattern first, then return code 1 without opening input files when the match semantics guarantee no selected lines. |
Closes #4.
-m 0means grep should stop before reading any input lines. In this case there can never be selected output, so after options and patterns are parsed and the matcher is compiled, the command can return the normal no-match exit before constructing the searcher or opening stdin/files.That placement is intentional: invalid patterns still report a regex error, while missing searched files are not touched for
-m 0. The-m 1path still opens inputs and reports missing-file errors as before.I added regression coverage for the missing-file short-circuit, the
-m 1control case, and invalid-pattern ordering.