forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recycle compression buffers (segmentio#320)
- Loading branch information
Achille
authored
Aug 9, 2019
1 parent
46aa607
commit b4c376a
Showing
3 changed files
with
62 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package kafka | ||
|
||
import ( | ||
"bytes" | ||
"sync" | ||
) | ||
|
||
var bufferPool = sync.Pool{ | ||
New: func() interface{} { return newBuffer() }, | ||
} | ||
|
||
func newBuffer() *bytes.Buffer { | ||
b := new(bytes.Buffer) | ||
b.Grow(65536) | ||
return b | ||
} | ||
|
||
func acquireBuffer() *bytes.Buffer { | ||
return bufferPool.Get().(*bytes.Buffer) | ||
} | ||
|
||
func releaseBuffer(b *bytes.Buffer) { | ||
if b != nil { | ||
b.Reset() | ||
bufferPool.Put(b) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ import ( | |
) | ||
|
||
const ( | ||
CompressionNoneCode = 0 | ||
|
||
compressionCodecMask = 0x07 | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters