use pointer to byte slices in the buffer pool

https://staticcheck.io/docs/staticcheck#SA6002 suggests to use pointers
to objects in the sync.Pool.
This commit is contained in:
Marten Seemann 2018-02-21 22:37:08 +08:00
parent d16dea09cc
commit 07b8821ef7
8 changed files with 21 additions and 30 deletions

View file

@ -8,25 +8,14 @@ import (
)
var _ = Describe("Buffer Pool", func() {
It("returns buffers of correct len and cap", func() {
buf := getPacketBuffer()
Expect(buf).To(HaveLen(0))
It("returns buffers of cap", func() {
buf := *getPacketBuffer()
Expect(buf).To(HaveCap(int(protocol.MaxReceivePacketSize)))
})
It("zeroes put buffers' length", func() {
for i := 0; i < 1000; i++ {
buf := getPacketBuffer()
putPacketBuffer(buf[0:10])
buf = getPacketBuffer()
Expect(buf).To(HaveLen(0))
Expect(buf).To(HaveCap(int(protocol.MaxReceivePacketSize)))
}
})
It("panics if wrong-sized buffers are passed", func() {
Expect(func() {
putPacketBuffer([]byte{0})
putPacketBuffer(&[]byte{0})
}).To(Panic())
})
})