/* Refills the input buffer. */
323686
func (t *StandardTokenizerImpl) zzRefill() (bool, error) {
	// first: make room (if you can)
	if t.zzStartRead > 0 {
		t.zzEndRead += t.zzFinalHighSurrogate
		t.zzFinalHighSurrogate = 0
		copy(t.zzBuffer, t.zzBuffer[t.zzStartRead:t.zzEndRead])

		// translate stored positions
		t.zzEndRead -= t.zzStartRead
		t.zzCurrentPos -= t.zzStartRead
		t.zzMarkedPos -= t.zzStartRead
		t.zzStartRead = 0
	}

	// fill the buffer with new input
	var requested = len(t.zzBuffer) - t.zzEndRead - t.zzFinalHighSurrogate
	var totalRead = 0
	var err error
	for totalRead < requested && err != io.EOF {
		var numRead int
		if numRead, err = readRunes(t.zzReader.(io.RuneReader),
			t.zzBuffer[t.zzEndRead+totalRead:]); err != nil && err != io.EOF {
			return false, err
		}
		totalRead += numRead
	}

	if totalRead > 0 {
		t.zzEndRead += totalRead
		if totalRead == requested { // possibly more input available
			panic("niy")
		}
		return false, nil
	}

	assert(totalRead == 0 && err == io.EOF)
	return true, nil
}
160572
func (buf *Buffer) Close() {
	zero(buf.buf, len(buf.buf))
	buf.buf = nil
}
1296388
func (queue *Queue) ResetInput() error {
	return queue.redisClient.Del(queueInputKey(queue.Name)).Err()
}
1126672
func Buffer(cfg *config.Config) (io.Writer, error) {
	size, found := cfg.Attrs["size"]
	if !found {
		return nil, argNotFoundErr("buffer", "size")
	}

	num, err := strconv.Atoi(size)
	if err != nil {
		return nil, err
	}

	return writers.NewBuffer(num), nil
}
1038552
func (ch *RingChannel) ringBuffer() {
	var input, output chan interface{}
	var next interface{}
	input = ch.input

	for input != nil || output != nil {
		select {
		// Prefer to write if possible, which is surprisingly effective in reducing
		// dropped elements due to overflow. The naive read/write select chooses randomly
		// when both channels are ready, which produces unnecessary drops 50% of the time.
		case output <- next:
			ch.buffer.Remove()
		default:
			select {
			case elem, open := <-input:
				if open {
					ch.buffer.Add(elem)
					if ch.size != Infinity && ch.buffer.Length() > int(ch.size) {
						ch.buffer.Remove()
					}
				} else {
					input = nil
				}
			case output <- next:
				ch.buffer.Remove()
			case ch.length <- ch.buffer.Length():
			}
		}

		if ch.buffer.Length() > 0 {
			output = ch.output
			next = ch.buffer.Peek()
		} else {
			output = nil
			next = nil
		}
	}

	close(ch.output)
	close(ch.length)
}
479154
func sourceFill(dinfo *C.struct_jpeg_decompress_struct) C.boolean {
	mgr := getSourceManager(dinfo)
	buffer := [readBufferSize]byte{}
	bytes, err := mgr.src.Read(buffer[:])
	C.memcpy(mgr.buffer, unsafe.Pointer(&buffer[0]), C.size_t(bytes))
	mgr.pub.bytes_in_buffer = C.size_t(bytes)
	mgr.currentSize = bytes
	mgr.pub.next_input_byte = (*C.JOCTET)(mgr.buffer)
	if err == io.EOF {
		if bytes == 0 {
			if mgr.startOfFile {
				releaseSourceManager(mgr)
				panic("input is empty")
			}
			// EOF and need more data. Fill in a fake EOI to get a partial image.
			footer := []byte{0xff, C.JPEG_EOI}
			C.memcpy(mgr.buffer, unsafe.Pointer(&footer[0]), C.size_t(len(footer)))
			mgr.pub.bytes_in_buffer = 2
		}
	} else if err != nil {
		releaseSourceManager(mgr)
		panic(err)
	}
	mgr.startOfFile = false

	return C.TRUE
}
1050807
func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) {
	return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) {
		key := event.Key()

		if (!t.rowsSelectable && !t.columnsSelectable && key == tcell.KeyEnter) ||
			key == tcell.KeyEscape ||
			key == tcell.KeyTab ||
			key == tcell.KeyBacktab {
			if t.done != nil {
				t.done(key)
			}
			return
		}

		// Movement functions.
		previouslySelectedRow, previouslySelectedColumn := t.selectedRow, t.selectedColumn
		var (
			getCell = func(row, column int) *TableCell {
				if row < 0 || column < 0 || row >= len(t.cells) || column >= len(t.cells[row]) {
					return nil
				}
				return t.cells[row][column]
			}

			previous = func() {
				for t.selectedRow >= 0 {
					cell := getCell(t.selectedRow, t.selectedColumn)
					if cell == nil || !cell.NotSelectable {
						return
					}
					t.selectedColumn--
					if t.selectedColumn < 0 {
						t.selectedColumn = t.lastColumn
						t.selectedRow--
					}
				}
			}

			next = func() {
				if t.selectedColumn > t.lastColumn {
					t.selectedColumn = 0
					t.selectedRow++
					if t.selectedRow >= len(t.cells) {
						t.selectedRow = len(t.cells) - 1
					}
				}
				for t.selectedRow < len(t.cells) {
					cell := getCell(t.selectedRow, t.selectedColumn)
					if cell == nil || !cell.NotSelectable {
						return
					}
					t.selectedColumn++
					if t.selectedColumn > t.lastColumn {
						t.selectedColumn = 0
						t.selectedRow++
					}
				}
				t.selectedColumn = t.lastColumn
				t.selectedRow = len(t.cells) - 1
				previous()
			}

			home = func() {
				if t.rowsSelectable {
					t.selectedRow = 0
					t.selectedColumn = 0
					next()
				} else {
					t.trackEnd = false
					t.rowOffset = 0
					t.columnOffset = 0
				}
			}

			end = func() {
				if t.rowsSelectable {
					t.selectedRow = len(t.cells) - 1
					t.selectedColumn = t.lastColumn
					previous()
				} else {
					t.trackEnd = true
					t.columnOffset = 0
				}
			}

			down = func() {
				if t.rowsSelectable {
					t.selectedRow++
					if t.selectedRow >= len(t.cells) {
						t.selectedRow = len(t.cells) - 1
					}
					next()
				} else {
					t.rowOffset++
				}
			}

			up = func() {
				if t.rowsSelectable {
					t.selectedRow--
					if t.selectedRow < 0 {
						t.selectedRow = 0
					}
					previous()
				} else {
					t.trackEnd = false
					t.rowOffset--
				}
			}

			left = func() {
				if t.columnsSelectable {
					t.selectedColumn--
					if t.selectedColumn < 0 {
						t.selectedColumn = 0
					}
					previous()
				} else {
					t.columnOffset--
				}
			}

			right = func() {
				if t.columnsSelectable {
					t.selectedColumn++
					if t.selectedColumn > t.lastColumn {
						t.selectedColumn = t.lastColumn
					}
					next()
				} else {
					t.columnOffset++
				}
			}

			pageDown = func() {
				if t.rowsSelectable {
					t.selectedRow += t.visibleRows
					if t.selectedRow >= len(t.cells) {
						t.selectedRow = len(t.cells) - 1
					}
					next()
				} else {
					t.rowOffset += t.visibleRows
				}
			}

			pageUp = func() {
				if t.rowsSelectable {
					t.selectedRow -= t.visibleRows
					if t.selectedRow < 0 {
						t.selectedRow = 0
					}
					previous()
				} else {
					t.trackEnd = false
					t.rowOffset -= t.visibleRows
				}
			}
		)

		switch key {
		case tcell.KeyRune:
			switch event.Rune() {
			case 'g':
				home()
			case 'G':
				end()
			case 'j':
				down()
			case 'k':
				up()
			case 'h':
				left()
			case 'l':
				right()
			}
		case tcell.KeyHome:
			home()
		case tcell.KeyEnd:
			end()
		case tcell.KeyUp:
			up()
		case tcell.KeyDown:
			down()
		case tcell.KeyLeft:
			left()
		case tcell.KeyRight:
			right()
		case tcell.KeyPgDn, tcell.KeyCtrlF:
			pageDown()
		case tcell.KeyPgUp, tcell.KeyCtrlB:
			pageUp()
		case tcell.KeyEnter:
			if (t.rowsSelectable || t.columnsSelectable) && t.selected != nil {
				t.selected(t.selectedRow, t.selectedColumn)
			}
		}

		// If the selection has changed, notify the handler.
		if t.selectionChanged != nil &&
			(t.rowsSelectable && previouslySelectedRow != t.selectedRow ||
				t.columnsSelectable && previouslySelectedColumn != t.selectedColumn) {
			t.selectionChanged(t.selectedRow, t.selectedColumn)
		}
	})
}
92255
func (c *Conn) BufferSize() int {
	if c.laddr.Buffered() {
		c.buf.configMu.RLock()
		defer c.buf.configMu.RUnlock()
		return c.buf.max
	}
	return 0
}
554469
func (rb *reorderBuffer) flushCopy(buf []byte) int {
	p := 0
	for i := 0; i < rb.nrune; i++ {
		runep := rb.rune[i]
		p += copy(buf[p:], rb.byte[runep.pos:runep.pos+runep.size])
	}
	rb.reset()
	return p
}
364853
func (buf *Buffer) Refresh() error {
	csbi := new(consoleScreenBufferInfo)
	ret, _, err := getConsoleScreenBufferInfo.Call(buf.Out.Fd(),
		uintptr(unsafe.Pointer(csbi)))
	if ret == 0 {
		return err
	}

	// If we're not echoing just write prompt.
	if !buf.Echo {
		err = buf.delLine(csbi)
		if err != nil {
			return err
		}

		err = buf.mvLeftEdge(csbi)
		if err != nil {
			return err
		}

		_, err = buf.Out.Write([]byte(buf.Prompt))
		return err
	}

	prLen := len(buf.Prompt)
	start := 0
	size := buf.size
	pos := buf.pos

	// Get slice range that should be visible.
	for prLen+pos >= buf.Cols {
		start++
		size--
		pos--
	}
	for prLen+size > buf.Cols {
		size--
	}

	err = buf.delLine(csbi)
	if err != nil {
		return err
	}

	err = buf.mvLeftEdge(csbi)
	if err != nil {
		return err
	}

	_, err = buf.Out.Write([]byte(buf.Prompt))
	if err != nil {
		return err
	}

	_, err = buf.Out.Write(toBytes(buf.data[start : size+start]))
	if err != nil {
		return err
	}

	return buf.mvToCol(csbi, pos+prLen)
}
820646
func (o *Osc) Fill(buf *audio.PCMBuffer) error {
	if o == nil {
		return nil
	}
	len := buf.Len()
	for i := 0; i < len; i++ {
		switch buf.DataType {
		case audio.Integer:
			buf.Ints[i] = int(o.Sample())
		case audio.Float:
			buf.Floats[i] = o.Sample()
		case audio.Byte:
			// TODO: check the format bitdepth and endianess and convert
			return errors.New("bytes buffer not yet supported")
		}
	}
	return nil
}
410115
func inputsToEmpties(arr []Input) []interface{} {
	ret := make([]interface{}, len(arr))
	for i, in := range arr {
		ret[i] = in
	}
	return ret
}
600651
func (evc *EventCache) Flush() {
	for _, ei := range evc.events {
		evc.evsw.FireEvent(ei.event, ei.data)
	}
	// Clear the buffer, since we only add to it with append it's safe to just set it to nil and maybe safe an allocation
	evc.events = nil
}
62462
func newBufferWithCap(initialCap int) *bytes.Buffer {
	initialBuf := make([]byte, 0, initialCap)
	return bytes.NewBuffer(initialBuf)
}
164371
func (b *buffer) readNext(need int) ([]byte, error) {
	if b.length < need {
		// refill
		if err := b.fill(need); err != nil {
			return nil, err
		}
	}

	offset := b.idx
	b.idx += need
	b.length -= need
	return b.buf[offset:b.idx], nil
}
74136
func (session *Session) BufferSize(size int) *Session {
	session.statement.bufferSize = size
	return session
}
62820
func (w *GatedWriter) Flush() {
	w.lock.Lock()
	w.flush = true
	w.lock.Unlock()

	for _, p := range w.buf {
		w.Write(p)
	}
	w.buf = nil
}