From adbf31e987abc889fa6aa298fffe7b7b8f4917e4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 07:59:37 +0100 Subject: [PATCH] ax(node): replace prose comments with usage examples in bufpool.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/node/bufpool.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/node/bufpool.go b/pkg/node/bufpool.go index a4f0e68..be8599a 100644 --- a/pkg/node/bufpool.go +++ b/pkg/node/bufpool.go @@ -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)