Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
[buffered encoder pool] Use an int for the maximum capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Froelich committed Aug 28, 2017
1 parent c373cff commit 7aa4c18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions protocol/msgpack/buffered_encoder_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package msgpack
import "github.com/m3db/m3x/pool"

type bufferedEncoderPool struct {
maxCapacity int64
maxCapacity int
pool pool.ObjectPool
}

Expand All @@ -46,7 +46,7 @@ func (p *bufferedEncoderPool) Get() BufferedEncoder {
}

func (p *bufferedEncoderPool) Put(encoder BufferedEncoder) {
if int64(encoder.Buffer().Cap()) > p.maxCapacity {
if encoder.Buffer().Cap() > p.maxCapacity {
return
}
p.pool.Put(encoder)
Expand Down
13 changes: 8 additions & 5 deletions protocol/msgpack/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

package msgpack

import xpool "github.com/m3db/m3x/pool"
import "math"
import (
"math"

xpool "github.com/m3db/m3x/pool"
)

const (
// The maximum capacity of buffers that can be returned to the buffered
Expand Down Expand Up @@ -49,7 +52,7 @@ const (
)

type bufferedEncoderPoolOptions struct {
maxCapacity int64
maxCapacity int
poolOpts xpool.ObjectPoolOptions
}

Expand All @@ -61,13 +64,13 @@ func NewBufferedEncoderPoolOptions() BufferedEncoderPoolOptions {
}
}

func (o *bufferedEncoderPoolOptions) SetMaxCapacity(value int64) BufferedEncoderPoolOptions {
func (o *bufferedEncoderPoolOptions) SetMaxCapacity(value int) BufferedEncoderPoolOptions {
opts := *o
opts.maxCapacity = value
return &opts
}

func (o *bufferedEncoderPoolOptions) MaxCapacity() int64 {
func (o *bufferedEncoderPoolOptions) MaxCapacity() int {
return o.maxCapacity
}

Expand Down
4 changes: 2 additions & 2 deletions protocol/msgpack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ type BufferedEncoderPool interface {
// BufferedEncoderPoolOptions provides options for buffered encoder pools.
type BufferedEncoderPoolOptions interface {
// SetMaxCapacity sets the maximum capacity of buffers that can be returned to the pool.
SetMaxCapacity(value int64) BufferedEncoderPoolOptions
SetMaxCapacity(value int) BufferedEncoderPoolOptions

// MaxBufferCapacity returns the maximum capacity of buffers that can be returned to the pool.
MaxCapacity() int64
MaxCapacity() int

// SetObjectPoolOptions sets the object pool options.
SetObjectPoolOptions(value pool.ObjectPoolOptions) BufferedEncoderPoolOptions
Expand Down

0 comments on commit 7aa4c18

Please sign in to comment.