Skip to content

Commit

Permalink
refactor: refactor comments for BufferPool class
Browse files Browse the repository at this point in the history
- Change the comment for `BufferPool` from "BufferPool is Pool of *bytes.Buffer" to "BufferPool represents a pool of buffers"
- Change the comment for `Get()` from "Get a bytes.Buffer pointer" to "Get returns a buffer from the buffer pool. If the pool is empty, a new buffer is created and returned"
- Change the comment for `Put()` from "Put a bytes.Buffer pointer to BufferPool" to "Put adds a buffer back to the pool"

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Nov 24, 2023
1 parent 3c14b06 commit df5d291
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"sync"
)

// BufferPool is Pool of *bytes.Buffer
// BufferPool represents a pool of buffers.
type BufferPool struct {
pool sync.Pool
}

// Get a bytes.Buffer pointer
// Get returns a buffer from the buffer pool.
// If the pool is empty, a new buffer is created and returned.
func (p *BufferPool) Get() *bytes.Buffer {
buf := p.pool.Get()
if buf == nil {
Expand All @@ -19,7 +20,7 @@ func (p *BufferPool) Get() *bytes.Buffer {
return buf.(*bytes.Buffer)
}

// Put a bytes.Buffer pointer to BufferPool
// Put adds a buffer back to the pool.
func (p *BufferPool) Put(buf *bytes.Buffer) {
p.pool.Put(buf)
}

0 comments on commit df5d291

Please sign in to comment.