hw-prim 0.6.2.12 → 0.6.2.13
raw patch · 2 files changed
+11/−40 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- hw-prim.cabal +1/−1
- src/HaskellWorks/Data/Vector/AsVector64.hs +10/−39
hw-prim.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hw-prim-version: 0.6.2.12+version: 0.6.2.13 synopsis: Primitive functions and data types description: Primitive functions and data types. category: Data
src/HaskellWorks/Data/Vector/AsVector64.hs view
@@ -4,11 +4,12 @@ ( AsVector64(..) ) where -import Data.Bits+import Data.Semigroup ((<>)) import Data.Word -import qualified Data.ByteString as BS-import qualified Data.Vector.Storable as DVS+import qualified Data.ByteString as BS+import qualified Data.ByteString.Internal as BSI+import qualified Data.Vector.Storable as DVS class AsVector64 a where asVector64 :: a -> DVS.Vector Word64@@ -18,40 +19,10 @@ {-# INLINE asVector64 #-} instance AsVector64 BS.ByteString where- asVector64 bs = DVS.constructN ((BS.length bs + 7) `div` 8) go- where go :: DVS.Vector Word64 -> Word64- go u = let bsi = DVS.length u * 8 in- if bsi + 8 <= BS.length bs- then let w0 = fromIntegral $ BS.index bs (bsi + 0)- w1 = fromIntegral $ BS.index bs (bsi + 1)- w2 = fromIntegral $ BS.index bs (bsi + 2)- w3 = fromIntegral $ BS.index bs (bsi + 3)- w4 = fromIntegral $ BS.index bs (bsi + 4)- w5 = fromIntegral $ BS.index bs (bsi + 5)- w6 = fromIntegral $ BS.index bs (bsi + 6)- w7 = fromIntegral $ BS.index bs (bsi + 7)- in (w0 `shiftL` 0) .|.- (w1 `shiftL` 8) .|.- (w2 `shiftL` 16) .|.- (w3 `shiftL` 24) .|.- (w4 `shiftL` 32) .|.- (w5 `shiftL` 40) .|.- (w6 `shiftL` 48) .|.- (w7 `shiftL` 56)- else let w0 = let i = bsi + 0 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 0) else 0- w1 = let i = bsi + 1 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 1) else 0- w2 = let i = bsi + 2 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 2) else 0- w3 = let i = bsi + 3 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 3) else 0- w4 = let i = bsi + 4 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 4) else 0- w5 = let i = bsi + 5 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 5) else 0- w6 = let i = bsi + 6 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 6) else 0- w7 = let i = bsi + 7 in if i < BS.length bs then fromIntegral $ BS.index bs (bsi + 7) else 0- in (w0 `shiftL` 0) .|.- (w1 `shiftL` 8) .|.- (w2 `shiftL` 16) .|.- (w3 `shiftL` 24) .|.- (w4 `shiftL` 32) .|.- (w5 `shiftL` 40) .|.- (w6 `shiftL` 48) .|.- (w7 `shiftL` 56)+ asVector64 bs = if vLen * 8 == BS.length bs+ then case BSI.toForeignPtr bs of+ (fptr, start, offset) -> DVS.unsafeCast (DVS.unsafeFromForeignPtr fptr start offset)+ else case BSI.toForeignPtr (bs <> BS.replicate (vLen * 8 - BS.length bs) 0) of+ (fptr, start, offset) -> DVS.unsafeCast (DVS.unsafeFromForeignPtr fptr start offset)+ where vLen = (BS.length bs + 7) `div` 8 {-# INLINE asVector64 #-}