MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Grow

Method Grow

pkg/sql/tokenizer/buffer.go:121–130  ·  view source on GitHub ↗

Grow ensures the buffer has enough capacity for n additional bytes. If the buffer doesn't have enough spare capacity, a new larger buffer is allocated with doubled capacity plus n bytes. The old buffer is returned to the pool. Growth Strategy: New capacity = 2 * old capacity + n This exponential g

(buf []byte, n int)

Source from the content-addressed store, hash-verified

119// buf = pool.Grow(buf, 256) // Ensure 256 bytes available
120// buf = append(buf, data...) // Append without reallocation
121func (p *BufferPool) Grow(buf []byte, n int) []byte {
122 if cap(buf)-len(buf) < n {
123 // Create new buffer with doubled capacity
124 newBuf := make([]byte, len(buf), 2*cap(buf)+n)
125 copy(newBuf, buf)
126 p.Put(buf) // Return old buffer to pool
127 return newBuf
128 }
129 return buf
130}

Callers 4

TestBufferPoolFunction · 0.95
stripDollarQuotedStringsFunction · 0.80
escapeStringLiteralFunction · 0.80

Calls 2

PutMethod · 0.95
copyFunction · 0.85

Tested by 2

TestBufferPoolFunction · 0.76