Skip to content

Commit

Permalink
plumbing: pktline, rename sync buffer getter putter
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 13, 2024
1 parent 452c784 commit c27492a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions plumbing/format/pktline/pktline.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func Read(r io.Reader, p []byte) (l int, err error) {
//
// The error can be of type *ErrorLine if the packet is an error packet.
func ReadLine(r io.Reader) (l int, p []byte, err error) {
buf := GetPacketBuffer()
defer PutPacketBuffer(buf)
buf := GetBuffer()
defer PutBuffer(buf)

l, err = Read(r, (*buf)[:])
if l < LenSize {
Expand Down
4 changes: 2 additions & 2 deletions plumbing/format/pktline/pktline_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BenchmarkReadPacket(b *testing.B) {
for _, tc := range cases {
r := strings.NewReader("")
b.Run(tc.name, func(b *testing.B) {
buf := pktline.GetPacketBuffer()
buf := pktline.GetBuffer()
for i := 0; i < b.N; i++ {
r.Reset(tc.input)
for {
Expand All @@ -113,7 +113,7 @@ func BenchmarkReadPacket(b *testing.B) {
}
}
}
pktline.PutPacketBuffer(buf)
pktline.PutBuffer(buf)
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions plumbing/format/pktline/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package pktline

import "sync"

var byteSlice = sync.Pool{
var pktBuffer = sync.Pool{
New: func() interface{} {
var b [MaxSize]byte
return &b
},
}

// GetPacketBuffer returns a *[MaxSize]byte that is managed by a
// sync.Pool. The initial slice length will be 65520 (65kb).
// GetBuffer returns a *[MaxSize]byte that is managed by a sync.Pool. The
// initial slice length will be 65520 (65kb).
//
// After use, the *[MaxSize]byte should be put back into the sync.Pool by
// calling PutByteSlice.
func GetPacketBuffer() *[MaxSize]byte {
buf := byteSlice.Get().(*[MaxSize]byte)
// calling PutBuffer.
func GetBuffer() *[MaxSize]byte {
buf := pktBuffer.Get().(*[MaxSize]byte)
return buf
}

// PutPacketBuffer puts buf back into its sync.Pool.
func PutPacketBuffer(buf *[MaxSize]byte) {
byteSlice.Put(buf)
// PutBuffer puts buf back into its sync.Pool.
func PutBuffer(buf *[MaxSize]byte) {
pktBuffer.Put(buf)
}

0 comments on commit c27492a

Please sign in to comment.