grep: keep only the requested number of before-context lines - #106
grep: keep only the requested number of before-context lines#106MsfPablo wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
|
Permit my rudeness but this is identical #69 and I find it funny in a sad way that both are the exact same type of wrong. Seriously, they're line-for-line identical, almost as if... it was written by the same entity. This is precisely why I'm jaded of AI-authored PRs: There's just... no variety anymore. They're all perfectly predictable within stochastic bounds. Same inputs expected outputs. And amnesia is built in as a feature. PR rejected. |
Fixes #66.
ContextBuffer::newrounds its slot count up to a power of two sopushcan mask instead of divide.pushthen capped the live length with.min(self.slots.len())— the rounded count — so the buffer retained up to the next power of two rather than the requested-B N. That is why-B 1/2/4/8looked correct while-B 3printed four lines.Kept the power-of-two slot allocation (the mask in
push/drain_iterdepends on it) and stored the requested capacity separately to boundlen.Diffed
-Band-Cfor N=1..8 against GNU grep on the issue's input: identical for every value. Added a regression test over N=3,5,6,7 — the non-power-of-two values, since the powers of two passed even with the bug.cargo test: 95 passed. clippy-D warningsandcargo fmt --checkclean.