// recycleBuf is called when the buffer is no longer needed to put it for reuse.
508967
func (r *bufferingReaderAt) recycleBuf(b []byte) {
	if cap(b) != r.blockSize {
		panic("trying to return a buffer not initially requested via grabBuf")
	}
	if len(r.pool)+1 > cap(r.pool) {
		panic("unexpected growth of byte buffer pool beyond capacity")
	}
	r.pool = append(r.pool, b[:cap(b)])
}
58655
func NewReadBuffer(gcInterval, expiryInterval time.Duration) *ReadBuffer {
	return &ReadBuffer{
		pool: NewRecycle(
			func() interface{} { return new(buffer.Read) },
			100, gcInterval, expiryInterval,
		),
	}
}
682927
func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS uint64) error {
	mvcc.mu.Lock()
	defer mvcc.mu.Unlock()

	batch := &leveldb.Batch{}
	err := rollbackKey(mvcc.db, batch, key, startTS)
	if err != nil {
		return errors.Trace(err)
	}
	return mvcc.db.Write(batch, nil)
}
1066437
func (s *summary) swapBufs(now time.Time) {
	if len(s.coldBuf) != 0 {
		panic("coldBuf is not empty")
	}
	s.hotBuf, s.coldBuf = s.coldBuf, s.hotBuf
	// hotBuf is now empty and gets new expiration set.
	for now.After(s.hotBufExpTime) {
		s.hotBufExpTime = s.hotBufExpTime.Add(s.streamDuration)
	}
}
95642
func ReadToBuf(scanner *bufio.Scanner) (*bytes.Buffer, error) {
	buf := new(bytes.Buffer)
	for scanner.Scan() {
		buf.WriteString(scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		return nil, err
	}
	return buf, nil
}
21607
func (c *Conn) recycleWritePacket() {
	if c.currentEphemeralPolicy != ephemeralWrite {
		// Programming error.
		panic(vterrors.Errorf(vtrpc.Code_INTERNAL, "trying to call recycleWritePacket while currentEphemeralPolicy is %d", c.currentEphemeralPolicy))
	}
	// Release our reference so the buffer can be gced
	bufPool.Put(c.currentEphemeralBuffer)
	c.currentEphemeralBuffer = nil
	c.currentEphemeralPolicy = ephemeralUnused
}
49594
func (m *MemoryStorer) cleanerLoop() {
	defer m.wg.Done()

	t, c := timerTestHarness(m.cleanInterval)

	select {
	case <-c:
		m.Clean()
		t.Reset(m.cleanInterval)
	case <-m.quit:
		t.Stop()
		return
	}
}
1229818
func (cvt *AudioCVT) AllocBuf(size uintptr) {
	cvt.Buf = C.malloc(C.size_t(size))
}
274952
func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error {
	var first = true

	buf.WriteString(`{`)
	if len(mj.Log) != 0 {
		first = false
		buf.WriteString(`"log":`)
		ffjsonWriteJSONBytesAsString(buf, mj.Log)
	}
	if len(mj.Stream) != 0 {
		if first {
			first = false
		} else {
			buf.WriteString(`,`)
		}
		buf.WriteString(`"stream":`)
		ffjsonWriteJSONBytesAsString(buf, []byte(mj.Stream))
	}
	if len(mj.RawAttrs) > 0 {
		if first {
			first = false
		} else {
			buf.WriteString(`,`)
		}
		buf.WriteString(`"attrs":`)
		buf.Write(mj.RawAttrs)
	}
	if !first {
		buf.WriteString(`,`)
	}

	created, err := fastTimeMarshalJSON(mj.Created)
	if err != nil {
		return err
	}

	buf.WriteString(`"time":`)
	buf.WriteString(created)
	buf.WriteString(`}`)
	return nil
}
565027
func (slocs SegmentLocs) DecRef() {
	for _, sloc := range slocs {
		if sloc.mref != nil {
			sloc.mref.DecRef()
		}
	}
}
952065
func (f *Function) cleanup() error {
	versionsToCleanup, err := f.versionsToCleanup()
	if err != nil {
		return err
	}

	return f.removeVersions(versionsToCleanup)
}
559264
func (s *asmState) resetBuf() {
	max := (cap(s.storage) / s.rate) * s.rate
	s.buf = s.storage[:0:max]
}
826166
func (s *BufferStore) WalkBuffer(f func(k Key, v []byte) error) error {
	return WalkMemBuffer(s.MemBuffer, f)
}
703020
func copyBuf(w io.Writer, r io.Reader) (int64, error) {
	buf := buffer32KPool.Get().([]byte)
	written, err := io.CopyBuffer(w, r, buf)
	buffer32KPool.Put(buf)
	return written, err
}
182431
func blobChunkCb(buffer *C.char, maxLen C.size_t, handle unsafe.Pointer) int {
	payload := pointerHandles.Get(handle)
	data, ok := payload.(*BlobCallbackData)
	if !ok {
		panic("could not retrieve blob callback data")
	}

	goBuf, err := data.Callback(int(maxLen))
	if err == io.EOF {
		return 0
	} else if err != nil {
		data.Error = err
		return -1
	}
	C.memcpy(unsafe.Pointer(buffer), unsafe.Pointer(&goBuf[0]), C.size_t(len(goBuf)))
	return len(goBuf)
}
781277
func (r *bufferingReaderAt) grabBuf() []byte {
	if len(r.pool) != 0 {
		b := r.pool[len(r.pool)-1]
		r.pool = r.pool[:len(r.pool)-1]
		return b
	}
	return make([]byte, r.blockSize)
}
1316468
func (r *Recycle) Return(item Recycler) {
	// Recycle the item to ensure that a dirty instance is never offered
	// from Take. The call is done here so that the CPU cycles spent
	// clearing the buffer are owned by the caller, and not by the queue
	// itself. This makes the queue more likely to be available to deliver
	// items in the free list.
	item.Recycle()

	r.queue.Return(item)
}