Skip to content

Commit d6ec1cd

Browse files
committed
move the pool values as well
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent 7a4679c commit d6ec1cd

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

pkg/file/file.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package file
22

33
// common values used across malcontent for extracting and reading files.
44
const (
5-
ExtractBuffer = 64 * 1024 // 64KB
6-
MaxBytes = 1 << 32 // 2048MB
7-
ReadBuffer int64 = 64 * 1024 // 64KB
8-
ZipBuffer = 2 * 1024 // 2KB
5+
DefaultPoolBuffer int = 4 * 1024 // 4KB
6+
ExtractBuffer = 64 * 1024 // 64KB
7+
MaxPoolBuffer int = 128 * 1024 // 128KB
8+
MaxBytes = 1 << 32 // 2048MB
9+
ReadBuffer int64 = 64 * 1024 // 64KB
10+
ZipBuffer = 2 * 1024 // 2KB
911
)

pkg/pool/pool.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import (
66
"sync"
77

88
yarax "github.com/VirusTotal/yara-x/go"
9-
)
10-
11-
const (
12-
defaultBuffer int = 4 * 1024 // 4KB
13-
maxBuffer int = 128 * 1024 // 128KB
9+
"github.com/chainguard-dev/malcontent/pkg/file"
1410
)
1511

1612
// BufferPool provides a pool of byte slices for use as buffers.
@@ -24,13 +20,13 @@ func NewBufferPool(count int) *BufferPool {
2420

2521
bp.pool = sync.Pool{
2622
New: func() any {
27-
buffer := make([]byte, defaultBuffer)
23+
buffer := make([]byte, file.DefaultPoolBuffer)
2824
return &buffer
2925
},
3026
}
3127

3228
for range count {
33-
buffer := make([]byte, defaultBuffer)
29+
buffer := make([]byte, file.DefaultPoolBuffer)
3430
bp.pool.Put(&buffer)
3531
}
3632

@@ -66,7 +62,7 @@ func (bp *BufferPool) Put(buf []byte) {
6662

6763
clear(buf)
6864
bufPtr := &buf
69-
if cap(*bufPtr) <= maxBuffer {
65+
if cap(*bufPtr) <= file.MaxPoolBuffer {
7066
bp.pool.Put(bufPtr)
7167
}
7268
}

0 commit comments

Comments
 (0)