mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 15:28:06 -05:00
gather: MakeContiguous support for arbitrary chunk sizes (#1247)
This commit is contained in:
@@ -41,8 +41,14 @@ func (b *WriteBuffer) MakeContiguous(length int) []byte {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
b.alloc = contiguousAllocator
|
||||
v := b.allocChunk()[0:length]
|
||||
var v []byte
|
||||
|
||||
if length > contiguousAllocator.chunkSize {
|
||||
v = make([]byte, length)
|
||||
} else {
|
||||
b.alloc = contiguousAllocator
|
||||
v = b.allocChunk()[0:length]
|
||||
}
|
||||
|
||||
b.inner.Slices = [][]byte{v}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGatherWriteBuffer(t *testing.T) {
|
||||
@@ -68,3 +70,14 @@ func TestGatherDefaultWriteBuffer(t *testing.T) {
|
||||
t.Errorf("invalid number of slices %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatherWriteBufferContig(t *testing.T) {
|
||||
var w WriteBuffer
|
||||
defer w.Close()
|
||||
|
||||
// allocate more than contig allocator can provide
|
||||
theCap := contiguousAllocator.chunkSize + 10
|
||||
b := w.MakeContiguous(theCap)
|
||||
require.Equal(t, theCap, len(b))
|
||||
require.Equal(t, theCap, cap(b))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user