// NewLookAheadBuffer returns a new LookAheadBuffer whose raw buffer has EXACTLY
// the specified size.
495984
func NewLookAheadBuffer(src io.Reader, bufferSize int) *LookAheadBuffer {
	return NewLookAheadBufferUsing(src, make([]byte, bufferSize, bufferSize))
}
583657
func NewBufferPool(size int, mem int) (bp *BufferPool) {
	return &BufferPool{
		c:     make(chan *bytes.Buffer, size),
		alloc: mem,
	}
}
546004
func NewEventQueueBuffered(name string, numBufferedEvents int) *EventQueue {
	log.WithFields(logrus.Fields{
		"name":              name,
		"numBufferedEvents": numBufferedEvents,
	}).Debug("creating new EventQueue")
	return &EventQueue{
		name: name,
		// Up to numBufferedEvents can be Enqueued until Enqueueing blocks.
		events: make(chan *Event, numBufferedEvents),
		close:  make(chan struct{}),
		drain:  make(chan struct{}),
	}

}
710980
func newCache(capacity int) *cache {
	if capacity <= 0 {
		capacity = MinCacheCapacity
	}
	return &cache{
		capacity: capacity,
		entries:  make(map[string]entry),
	}
}
889339
func newBufferedChecksumWithBuffer(in hash.Hash32, bufferSize int) *BufferedChecksum {
	return &BufferedChecksum{in: in, buffer: make([]byte, bufferSize)}
}
1330891
func newHashReader(h hash.Hash, r io.Reader) *hashReader {
	m := &hashReader{
		source: r,
		hash:   h,
	}
	return m
}
1231015
func (f *lightFetcher) newHeaders(headers []*types.Header, tds []*big.Int) {
	var maxTd *big.Int

	for p, fp := range f.peers {
		if !f.checkAnnouncedHeaders(fp, headers, tds) {
			p.Log().Debug("Inconsistent announcement")
			go f.pm.removePeer(p.id)
		}
		if fp.confirmedTd != nil && (maxTd == nil || maxTd.Cmp(fp.confirmedTd) > 0) {
			maxTd = fp.confirmedTd
		}
	}

	if maxTd != nil {
		f.updateMaxConfirmedTd(maxTd)
	}
}
1303485
func NewRingBuffer(
	capacity int,
	consolidateFunc MsgConsolidateFunc) *RingBuffer {
	return &RingBuffer{
		consolidateFunc: consolidateFunc,
		next:            0,
		msgs:            make([]Msg, capacity),
	}
}
1169305
func NewDisplayBuffer(Width, Height int) *DisplayBuffer {
	s := &DisplayBuffer{
		Width:  Width,
		Height: Height,
	}
	s.buffer = make([]byte, s.Size())
	return s
}
825589
func DecodeRxBufferHeader(b []byte) RxBuffer {
	return RxBuffer{
		Offset:   binary.LittleEndian.Uint64(b[postedOffset:]),
		Size:     binary.LittleEndian.Uint32(b[postedSize:]),
		ID:       binary.LittleEndian.Uint64(b[postedID:]),
		UserData: binary.LittleEndian.Uint64(b[postedUserData:]),
	}
}
355766
func NewHeader(text []byte, r []*Reference) (*Header, error) {
	var err error
	bh := &Header{
		refs:       r,
		seenRefs:   set{},
		seenGroups: set{},
		seenProgs:  set{},
	}
	for i, r := range bh.refs {
		if r.owner != nil || r.id >= 0 {
			return nil, errUsedReference
		}
		r.owner = bh
		r.id = int32(i)
	}
	if text != nil {
		err = bh.UnmarshalText(text)
		if err != nil {
			return nil, err
		}
	}
	return bh, nil
}
62462
func newBufferWithCap(initialCap int) *bytes.Buffer {
	initialBuf := make([]byte, 0, initialCap)
	return bytes.NewBuffer(initialBuf)
}
1133467
func NewLRUCache(capacity uint) *LRUCache {
	b := &LRUCache{}
	b.Init(capacity)
	return b
}
1148510
func NewGoMemcacher(c *memcache.Client) *GoMemcacher {
	if c == nil {
		panic("Cannot have nil memcache client")
	}
	return &GoMemcacher{client: c}
}
746692
func NewLLk(input string, k int) *LLk {
	c := lexer.New(input, 2*k) // +2 to keep a bit of buffer available.
	l := &LLk{
		k: k,
		c: c,
	}
	for i := 0; i < k+1; i++ {
		appendNextToken(l)
	}
	return l
}
764979
func newBuffer(size, numbuffers int) *buffer {
	return &buffer{
		size:    size,
		buffers: make([][]byte, 0, numbuffers),
		ptr:     -1,
	}
}
211271
func (pool *ByteBlockPool) NextBuffer() {
	if 1+pool.bufferUpto == len(pool.Buffers) {
		newBuffers := make([][]byte, Oversize(len(pool.Buffers)+1, NUM_BYTES_OBJECT_REF))
		copy(newBuffers, pool.Buffers)
		pool.Buffers = newBuffers
	}
	pool.Buffer = pool.allocator.allocate()
	pool.Buffers[1+pool.bufferUpto] = pool.Buffer
	pool.bufferUpto++

	pool.ByteUpto = 0
	pool.ByteOffset += BYTE_BLOCK_SIZE
}