From 0b6317a4f598e458dcc4ea8cb3944a1dd4f5c9f2 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Thu, 5 Sep 2019 09:09:45 -0400 Subject: [PATCH] Add a comment documenting the thought process behind encoding Word8s as decimal --- src/Data/ByteArray/Builder/Bounded.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Data/ByteArray/Builder/Bounded.hs b/src/Data/ByteArray/Builder/Bounded.hs index 764a36f..61ce345 100644 --- a/src/Data/ByteArray/Builder/Bounded.hs +++ b/src/Data/ByteArray/Builder/Bounded.hs @@ -172,7 +172,14 @@ word16Dec (W16# w) = wordCommonDec# w -- | 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. 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 -- as decimal. This encoding never starts with a zero unless the argument