ResizeTo grows the buffer to at least c and returns the new capacity, freeing the previous buffer back into pool.
(c uint32)
| 62 | // ResizeTo grows the buffer to at least c and returns the new capacity, freeing the |
| 63 | // previous buffer back into pool. |
| 64 | func (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. |
| 88 | func (b *WString) Buffer() []uint16 { |