aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-21 20:42:02 +0800
committerGravatar Runxi Yu2026-02-21 20:42:02 +0800
commit0f16511df2531d4d1d15434855bdd96b38021836 (patch)
tree25a901c8652f208947309cb2a56478bf6da2bbe0 /internal
parentobjectstore/packed: Don't use full delta reconstruction just to read headers (diff)
signatureNo signature
bufpool: Fix lints
Diffstat (limited to 'internal')
-rw-r--r--internal/bufpool/buffers.go6
-rw-r--r--internal/bufpool/buffers_test.go13
2 files changed, 15 insertions, 4 deletions
diff --git a/internal/bufpool/buffers.go b/internal/bufpool/buffers.go
index 439e7e04..59e8ed48 100644
--- a/internal/bufpool/buffers.go
+++ b/internal/bufpool/buffers.go
@@ -79,12 +79,13 @@ func Borrow(capHint int) Buffer {
newBuf := make([]byte, 0, capHint)
return Buffer{buf: newBuf, pool: unpooled}
}
+ //nolint:forcetypeassert
buf := bufferPools[classIdx].Get().(*[]byte)
if cap(*buf) < classCap {
*buf = make([]byte, 0, classCap)
}
slice := (*buf)[:0]
- return Buffer{buf: slice, pool: poolIndex(classIdx)}
+ return Buffer{buf: slice, pool: poolIndex(classIdx)} //#nosec:G115
}
// FromOwned constructs a Buffer from a caller-owned byte slice. The resulting
@@ -153,6 +154,7 @@ func (buf *Buffer) ensureCapacity(needed int) {
classIdx, classCap, pooled := classFor(needed)
var newBuf []byte
if pooled {
+ //nolint:forcetypeassert
raw := bufferPools[classIdx].Get().(*[]byte)
if cap(*raw) < classCap {
*raw = make([]byte, 0, classCap)
@@ -165,7 +167,7 @@ func (buf *Buffer) ensureCapacity(needed int) {
buf.returnToPool()
buf.buf = newBuf
if pooled {
- buf.pool = poolIndex(classIdx)
+ buf.pool = poolIndex(classIdx) //#nosec:G115
} else {
buf.pool = unpooled
}
diff --git a/internal/bufpool/buffers_test.go b/internal/bufpool/buffers_test.go
index f5c006da..a690aad1 100644
--- a/internal/bufpool/buffers_test.go
+++ b/internal/bufpool/buffers_test.go
@@ -1,8 +1,11 @@
+//nolint:testpackage
package bufpool
import "testing"
func TestBorrowBufferResizeAndAppend(t *testing.T) {
+ t.Parallel()
+
b := Borrow(1)
defer b.Release()
@@ -31,6 +34,8 @@ func TestBorrowBufferResizeAndAppend(t *testing.T) {
}
func TestBorrowBufferRelease(t *testing.T) {
+ t.Parallel()
+
b := Borrow(DefaultBufferCap / 2)
b.Append([]byte("data"))
b.Release()
@@ -40,6 +45,8 @@ func TestBorrowBufferRelease(t *testing.T) {
}
func TestBorrowUsesLargerPools(t *testing.T) {
+ t.Parallel()
+
const request = DefaultBufferCap * 4
classIdx, classCap, pooled := classFor(request)
@@ -48,7 +55,7 @@ func TestBorrowUsesLargerPools(t *testing.T) {
}
b := Borrow(request)
- if b.pool != poolIndex(classIdx) {
+ if b.pool != poolIndex(classIdx) { //#nosec:G115
t.Fatalf("expected pooled buffer in class %d, got %d", classIdx, b.pool)
}
if cap(b.buf) != classCap {
@@ -58,7 +65,7 @@ func TestBorrowUsesLargerPools(t *testing.T) {
b2 := Borrow(request)
defer b2.Release()
- if b2.pool != poolIndex(classIdx) {
+ if b2.pool != poolIndex(classIdx) { //#nosec:G115
t.Fatalf("expected pooled buffer in class %d on reuse, got %d", classIdx, b2.pool)
}
if cap(b2.buf) != classCap {
@@ -67,6 +74,8 @@ func TestBorrowUsesLargerPools(t *testing.T) {
}
func TestGrowingBufferStaysPooled(t *testing.T) {
+ t.Parallel()
+
b := Borrow(DefaultBufferCap)
defer b.Release()