File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{-# language DataKinds #-}
2+ {-# language MagicHash #-}
23{-# language TypeOperators #-}
34
45module Data.Bytes.Indexed
56 ( ByteArrayN
67 , append
8+ , length
9+ , length #
710 ) where
811
12+ import Prelude hiding (length )
13+
14+ import Data.Primitive (ByteArray (ByteArray ))
915import Data.Bytes.Types (ByteArrayN (ByteArrayN ))
1016import GHC.TypeNats (type (+ ))
17+ import Arithmetic.Types (Nat , Nat #)
18+
19+ import qualified Data.Primitive as PM
20+ import qualified Arithmetic.Unsafe as Unsafe
21+ import qualified GHC.Exts as Exts
1122
1223append :: ByteArrayN m -> ByteArrayN n -> ByteArrayN (m + n )
1324{-# inline append #-}
1425append (ByteArrayN x) (ByteArrayN y) = ByteArrayN (x <> y)
26+
27+ -- | Recover a witness of the length.
28+ length :: ByteArrayN n -> Nat n
29+ {-# inline length #-}
30+ length (ByteArrayN x) = Unsafe. Nat (PM. sizeofByteArray x)
31+
32+ -- | Recover an unboxed witness of the length.
33+ length # :: ByteArrayN n -> Nat # n
34+ {-# inline length# #-}
35+ length # (ByteArrayN (ByteArray x)) = Unsafe. Nat# (Exts. sizeofByteArray# x)
You can’t perform that action at this time.
0 commit comments