Create a
Builder that encodes values with the given
BoundedPrim.
We rewrite consecutive uses of
primBounded such that the
bound-checks are fused. For example,
primBounded (word32 c1) `mappend` primBounded (word32 c2)
is rewritten such that the resulting
Builder checks only once,
if ther are at 8 free bytes, instead of checking twice, if there are 4
free bytes. This optimization is not observationally equivalent in a
strict sense, as it influences the boundaries of the generated chunks.
However, for a user of this library it is observationally equivalent,
as chunk boundaries of a
LazyByteString can only be observed
through the internal interface. Moreover, we expect that all
primitives write much fewer than 4kb (the default short buffer size).
Hence, it is safe to ignore the additional memory spilled due to the
more aggressive buffer wrapping introduced by this optimization.