1
0
mirror of https://github.com/Oxalide/vsphere-influxdb-go.git synced 2023-10-10 11:36:51 +00:00

add vendoring with go dep

This commit is contained in:
Adrian Todorov
2017-10-25 20:52:40 +00:00
parent 704f4d20d1
commit a59409f16b
1627 changed files with 489673 additions and 0 deletions

100
vendor/github.com/influxdata/influxdb/pkg/pool/bytes.go generated vendored Normal file
View File

@@ -0,0 +1,100 @@
// Package pool provides pool structures to help reduce garbage collector pressure.
package pool
// Bytes is a pool of byte slices that can be re-used. Slices in
// this pool will not be garbage collected when not in use.
type Bytes struct {
pool chan []byte
}
// NewBytes returns a Bytes pool with capacity for max byte slices
// to be pool.
func NewBytes(max int) *Bytes {
return &Bytes{
pool: make(chan []byte, max),
}
}
// Get returns a byte slice size with at least sz capacity. Items
// returned may not be in the zero state and should be reset by the
// caller.
func (p *Bytes) Get(sz int) []byte {
var c []byte
select {
case c = <-p.pool:
default:
return make([]byte, sz)
}
if cap(c) < sz {
return make([]byte, sz)
}
return c[:sz]
}
// Put returns a slice back to the pool. If the pool is full, the byte
// slice is discarded.
func (p *Bytes) Put(c []byte) {
select {
case p.pool <- c:
default:
}
}
// LimitedBytes is a pool of byte slices that can be re-used. Slices in
// this pool will not be garbage collected when not in use. The pool will
// hold onto a fixed number of byte slices of a maximum size. If the pool
// is empty and max pool size has not been allocated yet, it will return a
// new byte slice. Byte slices added to the pool that are over the max size
// are dropped.
type LimitedBytes struct {
allocated int64
maxSize int
pool chan []byte
}
// NewBytes returns a Bytes pool with capacity for max byte slices
// to be pool.
func NewLimitedBytes(capacity int, maxSize int) *LimitedBytes {
return &LimitedBytes{
pool: make(chan []byte, capacity),
maxSize: maxSize,
}
}
// Get returns a byte slice size with at least sz capacity. Items
// returned may not be in the zero state and should be reset by the
// caller.
func (p *LimitedBytes) Get(sz int) []byte {
var c []byte
// If we have not allocated our capacity, return a new allocation,
// otherwise block until one frees up.
select {
case c = <-p.pool:
default:
return make([]byte, sz)
}
if cap(c) < sz {
return make([]byte, sz)
}
return c[:sz]
}
// Put returns a slice back to the pool. If the pool is full, the byte
// slice is discarded. If the byte slice is over the configured max size
// of any byte slice in the pool, it is discared.
func (p *LimitedBytes) Put(c []byte) {
// Drop buffers that are larger than the max size
if cap(c) >= p.maxSize {
return
}
select {
case p.pool <- c:
default:
}
}

View File

@@ -0,0 +1,16 @@
package pool_test
import (
"testing"
"github.com/influxdata/influxdb/pkg/pool"
)
func TestLimitedBytePool_Put_MaxSize(t *testing.T) {
bp := pool.NewLimitedBytes(1, 10)
bp.Put(make([]byte, 1024)) // should be dropped
if got, exp := cap(bp.Get(10)), 10; got != exp {
t.Fatalf("max cap size exceeded: got %v, exp %v", got, exp)
}
}

View File

@@ -0,0 +1,40 @@
package pool
// Generic is a pool of types that can be re-used. Items in
// this pool will not be garbage collected when not in use.
type Generic struct {
pool chan interface{}
fn func(sz int) interface{}
}
// NewGeneric returns a Generic pool with capacity for max items
// to be pool.
func NewGeneric(max int, fn func(sz int) interface{}) *Generic {
return &Generic{
pool: make(chan interface{}, max),
fn: fn,
}
}
// Get returns a item from the pool or a new instance if the pool
// is empty. Items returned may not be in the zero state and should
// be reset by the caller.
func (p *Generic) Get(sz int) interface{} {
var c interface{}
select {
case c = <-p.pool:
default:
c = p.fn(sz)
}
return c
}
// Put returns an item back to the pool. If the pool is full, the item
// is discarded.
func (p *Generic) Put(c interface{}) {
select {
case p.pool <- c:
default:
}
}