Skip to content

chore: housekeeping — doc fixes, Iterator lock, modulo and MarshalJSON cleanups#59

Merged
adrianbrad merged 3 commits intomainfrom
chore/housekeeping
Apr 21, 2026
Merged

chore: housekeeping — doc fixes, Iterator lock, modulo and MarshalJSON cleanups#59
adrianbrad merged 3 commits intomainfrom
chore/housekeeping

Conversation

@adrianbrad
Copy link
Copy Markdown
Owner

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 the Circular guard.
  • linked.goIsEmpty doc comment above the isEmpty private helper.

Lock ordering

  • Linked.Iterator was calling Clear (which acquired and released the lock) and then building the channel outside any lock. Other queues hold the lock for the whole call. Extracted a drainLocked helper shared by Clear and Iterator.

Perf tweaks

  • Circular.Contains and Circular.MarshalJSON now walk in two contiguous chunks (head..end, then 0..tail) instead of doing a modulo per element.
  • Priority.MarshalJSON sorts a copy with sort.Slice instead of heap.Init + N heap.Pop calls. Same output, fewer allocations.
  • blocking.go drops the one-line size() helper used only inside Iterator; replaced with len(bq.elems).

Tests

  • Added a Circular.Contains sub-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% statements
  • golangci-lint run passes

- 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
Copy link
Copy Markdown

codecov bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b458967) to head (0a01090).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adrianbrad adrianbrad merged commit e10179f into main Apr 21, 2026
10 checks passed
@adrianbrad adrianbrad deleted the chore/housekeeping branch April 21, 2026 09:07
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.

1 participant