Add a comment documenting the thought process behind encoding Word8s as decimal

This commit is contained in:
Andrew Martin 2019-09-05 09:09:45 -04:00
parent 61871a9ae3
commit 0b6317a4f5

View file

@ -172,7 +172,14 @@ word16Dec (W16# w) = wordCommonDec# w
-- | Requires up to 3 bytes. Encodes an unsigned 8-bit integer as decimal. -- | Requires up to 3 bytes. Encodes an unsigned 8-bit integer as decimal.
-- This encoding never starts with a zero unless the argument was zero. -- This encoding never starts with a zero unless the argument was zero.
word8Dec :: Word8 -> Builder 3 word8Dec :: Word8 -> Builder 3
word8Dec (W8# w) = word8Dec# w word8Dec (W8# w) =
-- We unroll the loop when encoding Word8s. This speeds things
-- up IPv4 encoding by about 10% in the @ip@ library. We can
-- encode Word8s at twice this speed by using a lookup table.
-- However, I (Andrew Martin) am concerned that although lookup
-- table perform very well in microbenchmarks, they can thrash
-- L1 cache in real applications.
word8Dec# w
-- | Requires up to 19 bytes. Encodes an unsigned machine-sized integer -- | Requires up to 19 bytes. Encodes an unsigned machine-sized integer
-- as decimal. This encoding never starts with a zero unless the argument -- as decimal. This encoding never starts with a zero unless the argument