Skip to content

grep: keep only the requested number of before-context lines - #106

Closed
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:before-context-exact-count
Closed

grep: keep only the requested number of before-context lines#106
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:before-context-exact-count

Conversation

@MsfPablo

Copy link
Copy Markdown

Fixes #66.

ContextBuffer::new rounds its slot count up to a power of two so push can mask instead of divide. push then 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/8 looked correct while -B 3 printed four lines.

Kept the power-of-two slot allocation (the mask in push/drain_iter depends on it) and stored the requested capacity separately to bound len.

$ printf '01\n...\n10\nMM\n' | grep -e MM -B 3
08
09
10
MM

Diffed -B and -C for 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 warnings and cargo fmt --check clean.

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing MsfPablo:before-context-exact-count (408ba6a) with main (5882b3d)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@lhecker

lhecker commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

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.

@lhecker lhecker closed this Aug 18, 2026
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.

-B/-C before-context count is rounded up to a power of two

2 participants