chore: housekeeping — doc fixes, Iterator lock, modulo and MarshalJSON cleanups#59
Merged
adrianbrad merged 3 commits intomainfrom Apr 21, 2026
Merged
chore: housekeeping — doc fixes, Iterator lock, modulo and MarshalJSON cleanups#59adrianbrad merged 3 commits intomainfrom
adrianbrad merged 3 commits intomainfrom
Conversation
- doc.go: package overview said "2 available implementations" but describes 4. Also drop the inaccurate "Lesser interface" line — Priority takes a less function at construction, not an interface. - circular.go: Queue-implementation guard's doc comment said "Ensure Priority implements..." (copy-paste from priority.go). - linked.go: comment above isEmpty() said "IsEmpty returns true...". Refs #47
Iterator was calling Clear, which acquired and released the write lock, then built the channel outside any lock. The other queue implementations hold their lock for the duration of Iterator; this brings Linked in line. Extracted the drain into a locked helper so Clear can share it. Refs #47
- circular.go: walk Contains/MarshalJSON in two contiguous chunks instead of computing modulo per element. - priority.go: MarshalJSON sorts a copy with sort.Slice instead of heap.Init + N heap.Pop. Same output, fewer allocations and a cache-friendlier loop. - blocking.go: drop the unused-elsewhere size() helper; the only caller was Iterator and len(bq.elems) is just as readable. No behaviour changes. Adds a Circular.Contains test for the wrap-around chunk so the new branch is exercised. Refs #47
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 478 483 +5
=========================================
+ Hits 478 483 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bundle of small cleanups from the umbrella issue. No behaviour changes; all existing tests pass and coverage stays at 100%.
Docs / comments
doc.go— package overview claimed "2 available implementations" but described 4. Also dropped the inaccurate "Lesser interface" reference.circular.go:8— copy-paste typo: "Ensure Priority implements..." on theCircularguard.linked.go—IsEmptydoc comment above theisEmptyprivate helper.Lock ordering
Linked.Iteratorwas callingClear(which acquired and released the lock) and then building the channel outside any lock. Other queues hold the lock for the whole call. Extracted adrainLockedhelper shared byClearandIterator.Perf tweaks
Circular.ContainsandCircular.MarshalJSONnow walk in two contiguous chunks (head..end, then 0..tail) instead of doing a modulo per element.Priority.MarshalJSONsorts a copy withsort.Sliceinstead ofheap.Init+ Nheap.Popcalls. Same output, fewer allocations.blocking.godrops the one-linesize()helper used only insideIterator; replaced withlen(bq.elems).Tests
Circular.Containssub-test that exercises the wrap-around chunk so the new branch is covered.Refs #47
Test plan
go test -race -shuffle=on .go test -coverprofile— 100% statementsgolangci-lint runpasses