ax(node): replace prose comments with usage examples in bufpool.go

AX Principle 2 — comments must show HOW with real values, not describe
WHAT the signature already says. Replaced three prose descriptions on
getBuffer, putBuffer, and MarshalJSON with concrete call-site examples.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 07:59:37 +01:00
parent edcee49435
commit adbf31e987
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -14,14 +14,15 @@ var bufferPool = sync.Pool{
},
}
// getBuffer retrieves a buffer from the pool.
// buf := getBuffer()
// defer putBuffer(buf)
func getBuffer() *bytes.Buffer {
buf := bufferPool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
// putBuffer returns a buffer to the pool.
// putBuffer(buf) // always called via defer after getBuffer()
func putBuffer(buf *bytes.Buffer) {
// Don't pool buffers that grew too large (>64KB)
if buf.Cap() <= 65536 {
@ -29,8 +30,8 @@ func putBuffer(buf *bytes.Buffer) {
}
}
// MarshalJSON encodes a value to JSON using a pooled buffer.
// Returns a copy of the encoded bytes (safe to use after the function returns).
// data, err := MarshalJSON(msg)
// if err != nil { return nil, err }
func MarshalJSON(v interface{}) ([]byte, error) {
buf := getBuffer()
defer putBuffer(buf)