Fast implementation of Git in pure Go
at master 24 lines 934 B view raw
1package bufpool 2 3// Buffer is a growable byte container that optionally participates in a 4// memory pool. A Buffer may be obtained through Borrow() or constructed 5// directly from owned data via FromOwned(). 6// 7// A Buffer's underlying slice may grow as needed. When finished with a 8// pooled buffer, the caller should invoke Release() to return it to the pool. 9// 10// Buffers must not be copied after first use; doing so can cause double-returns 11// to the pool and data races. 12// 13// In general, pass Buffer around when used internally, and directly .Bytes() when 14// returning output across our API boundary. It is neither necessary nor efficient 15// to copy/append the .Bytes() to a newly-allocated slice; in cases where we do 16// want the raw byte slice out of our API boundary, it is perfectly acceptable to 17// simply not call Release(). 18// 19//go:nocopy 20type Buffer struct { 21 _ struct{} // for nocopy 22 buf []byte 23 pool poolIndex 24}