Replace monomorphic buffer functions with generic#9
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the iobuf package to replace 36 type-specific buffer functions with 3 generic implementations using Go generics and the existing BufferType constraint. The refactoring significantly reduces code duplication while maintaining full test coverage and functionality.
Changes:
- Consolidated 12
IoVecFrom*Buffersfunctions into a single genericIoVecFrom[T BufferType]function - Consolidated 12
*ArrayFromSlicefunctions into a single genericArrayFromSlice[T BufferType]function - Consolidated 12
SliceOf*Arrayfunctions into a single genericSliceOfArray[T BufferType]function - Updated Go version requirement from 1.25 to 1.26 (throughout all documentation, CI, and module files)
- Modernized loop syntax from
for i := range len(slice)tofor i := range slice - Changed
BoundedPoolItemfrominterface{}toany(type alias) - Updated all tests and benchmarks to use the new generic functions
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Bumped Go version to 1.26 and updated dependencies to v0.3.3 and v0.1.5 |
| go.sum | Updated checksums for new dependency versions |
| iovec.go | Replaced 12 monomorphic IoVecFrom functions with single generic implementation using unsafe.Sizeof |
| iovec_test.go | Consolidated 12 separate test functions into one unified TestIoVecFrom with subtests for all buffer types |
| buffers.go | Replaced 24 monomorphic array conversion functions with 2 generic implementations |
| buffers_test.go | Consolidated tests into unified TestArrayFromSlice and TestSliceOfArray with subtests, simplified panic tests |
| bounded_pool.go | Changed BoundedPoolItem from interface{} to any type alias with updated documentation |
| benchmark_test.go | Updated benchmarks to use generic functions and modernized loop syntax |
| README.md | Updated Go version requirement to 1.26 |
| README.*.md | Updated Go version requirement to 1.26 in all language variants |
| .github/workflows/ci.yml | Updated CI to use Go 1.26.x |
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
Unify 36 type-specific buffer functions into 3 generics using the existing
BufferTypeconstraint.Changes
IoVecFrom*BufferswithIoVecFrom[T BufferType]*ArrayFromSlicewithArrayFromSlice[T BufferType]SliceOf*ArraywithSliceOfArray[T BufferType]Test plan
go test -count=1 -race ./...passesgo vet ./...clean