MCPcopy Create free account
hub / github.com/microsoft/go-winio / ResizeTo

Method ResizeTo

internal/stringbuffer/wstring.go:64–85  ·  view source on GitHub ↗

ResizeTo grows the buffer to at least c and returns the new capacity, freeing the previous buffer back into pool.

(c uint32)

Source from the content-addressed store, hash-verified

62// ResizeTo grows the buffer to at least c and returns the new capacity, freeing the
63// previous buffer back into pool.
64func (b *WString) ResizeTo(c uint32) uint32 {
65 // already sufficient (or n is 0)
66 if c <= b.Cap() {
67 return b.Cap()
68 }
69
70 if c <= MinWStringCap {
71 c = MinWStringCap
72 }
73 // allocate at-least double buffer size, as is done in [bytes.Buffer] and other places
74 if c <= 2*b.Cap() {
75 c = 2 * b.Cap()
76 }
77
78 b2 := make([]uint16, c)
79 if !b.empty() {
80 copy(b2, b.b)
81 freeBuffer(b.b)
82 }
83 b.b = b2
84 return c
85}
86
87// Buffer returns the underlying []uint16 buffer.
88func (b *WString) Buffer() []uint16 {

Callers 2

GetFinalPathNameByHandleFunction · 0.95
Test_BufferCapacityFunction · 0.95

Calls 3

CapMethod · 0.95
emptyMethod · 0.95
freeBufferFunction · 0.85

Tested by 1

Test_BufferCapacityFunction · 0.76