on master help sign in
Use cacheline aligned lookup table

It makes a barely noticeable difference.

commit069728c6210234258276c37b9e87be0bdb94ecc9 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 19 Sep 2019, 02:20 (7 years ago) parente12c864
1 file changed+7−1
src/Streamly/Streams/StreamD.hs+7−1
src/Streamly/Streams/StreamD.hs+7−1
@@ -288,6 +288,7 @@ import GHC.Base (assert, Char(..), unsafeChr, ord)
288288import GHC.IO.Encoding.Failure (isSurrogate)
289289import GHC.Types (SPEC(..))
290290import GHC.Word (Word8(..))
291+import System.IO.Unsafe (unsafePerformIO)
291292import Prelude
292293 hiding (map, mapM, mapM_, repeat, foldr, last, take, filter,
293294 takeWhile, drop, dropWhile, all, any, maximum, minimum, elem,
@@ -3015,8 +3016,13 @@ type DecoderState = Word8
30153016
30163017-- See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
30173018
3019+{-# INLINE runFold #-}
3020+runFold :: (Monad m) => Fold m a b -> Stream m a -> m b
3021+runFold (Fold step begin done) = foldlMx' step begin done
3022+
3023+-- Aligning to cacheline makes a barely noticeable difference
30183024utf8d :: A.Array Word8
3019−utf8d = A.fromList [
3025+utf8d = unsafePerformIO $ runFold (A.writeAligned 64) $ fromList [
30203026 -- The first part of the table maps bytes to character classes that
30213027 -- to reduce the size of the transition table and create bitmasks.
30223028 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,