MCPcopy
hub / github.com/kopia/kopia / MakeContiguous

Method MakeContiguous

internal/gather/gather_write_buffer.go:38–63  ·  view source on GitHub ↗

MakeContiguous ensures the write buffer consists of exactly one contiguous single slice of the provided length and returns the slice.

(length int)

Source from the content-addressed store, hash-verified

36// MakeContiguous ensures the write buffer consists of exactly one contiguous single slice of the provided length
37// and returns the slice.
38func (b *WriteBuffer) MakeContiguous(length int) []byte {
39 b.Reset()
40
41 b.mu.Lock()
42 defer b.mu.Unlock()
43
44 var v []byte
45
46 switch {
47 case length <= typicalContiguousAllocator.chunkSize:
48 // most commonly used allocator for default chunk size with max 8MB
49 b.alloc = typicalContiguousAllocator
50 v = b.allocChunk()[0:length]
51
52 case length <= maxContiguousAllocator.chunkSize:
53 b.alloc = maxContiguousAllocator
54 v = b.allocChunk()[0:length]
55
56 default:
57 v = make([]byte, length)
58 }
59
60 b.inner.Slices = [][]byte{v}
61
62 return v
63}
64
65// Reset resets buffer back to empty.
66func (b *WriteBuffer) Reset() {

Callers 7

PutIfAbsentMethod · 0.95
EncryptMethod · 0.95
DecryptMethod · 0.95
aeadSealWithRandomNonceFunction · 0.95

Calls 4

ResetMethod · 0.95
allocChunkMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65