Documentation
¶
Overview ¶
Package zeroio provides helpers for writing and scanning runs of zero bytes, sharing a single zero-filled buffer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstNonZero ¶
FirstNonZero returns the index of the first non-zero byte in p, or len(p) if every byte is zero.
Whole zeroes-sized chunks are skipped with bytes.Equal, which lowers to the SIMD memequal assembly and clears all-zero data at memory-bandwidth speed; the first non-zero chunk (and any tail) is then scanned a word at a time. LittleEndian.Uint64 places p[i] in the low byte on every platform, so TrailingZeros64/8 is the first non-zero byte index regardless of machine endianness.
func WriteZeroes ¶
WriteZeroes writes n zero bytes to w. If w implements ZeroesWriter it's delegated to, letting w absorb the run without the bytes being materialized; otherwise the zeroes are written from a shared buffer, so unlike io.CopyN with a zero reader it doesn't allocate or re-zero a buffer per call.
func WriteZeroesNoFastPath ¶
WriteZeroesNoFastPath writes n zero bytes to w from the shared buffer, without consulting ZeroesWriter (the fast path). A ZeroesWriter implementation that ultimately writes into an underlying io.Writer should call this rather than WriteZeroes, so it can't re-enter the dispatch and recurse.
Types ¶
type ZeroesWriter ¶
ZeroesWriter is implemented by writers that can absorb a run of zeroes without having them materialized, e.g. by extending a sparse file or accumulating a count. WriteZeroes prefers it.