memory 0.14.8 → 0.14.9
raw patch · 5 files changed
+41/−41 lines, 5 filesdep +basementdep −foundationdep ~base
Dependencies added: basement
Dependencies removed: foundation
Dependency ranges changed: base
Files
- CHANGELOG.md +4/−0
- Data/ByteArray/Bytes.hs +13/−0
- Data/ByteArray/ScrubbedBytes.hs +12/−0
- Data/ByteArray/Types.hs +10/−29
- memory.cabal +2/−12
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.14.9++* Reduce dependency to basement+ ## 0.14.8 * Fix incompatibility with foundation 0.0.14
Data/ByteArray/Bytes.hs view
@@ -7,6 +7,7 @@ -- -- Simple and efficient byte array types --+{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-}@@ -17,7 +18,12 @@ import GHC.Types import GHC.Prim import GHC.Ptr+#if MIN_VERSION_base(4,9,0)+import Data.Semigroup+import Data.Foldable (toList)+#else import Data.Monoid+#endif import Data.Memory.PtrMethods import Data.Memory.Internal.Imports import Data.Memory.Internal.CompatPrim@@ -33,10 +39,17 @@ (==) = bytesEq instance Ord Bytes where compare = bytesCompare+#if MIN_VERSION_base(4,9,0)+instance Semigroup Bytes where+ b1 <> b2 = unsafeDoIO $ bytesAppend b1 b2+ sconcat = unsafeDoIO . bytesConcat . toList+#endif instance Monoid Bytes where mempty = unsafeDoIO (newBytes 0)+#if !(MIN_VERSION_base(4,11,0)) mappend b1 b2 = unsafeDoIO $ bytesAppend b1 b2 mconcat = unsafeDoIO . bytesConcat+#endif instance NFData Bytes where rnf b = b `seq` () instance ByteArrayAccess Bytes where
Data/ByteArray/ScrubbedBytes.hs view
@@ -16,7 +16,12 @@ import GHC.Types import GHC.Prim import GHC.Ptr+#if MIN_VERSION_base(4,9,0)+import Data.Semigroup+import Data.Foldable (toList)+#else import Data.Monoid+#endif import Data.String (IsString(..)) import Data.Memory.PtrMethods (memCopy, memConstEqual) import Data.Memory.Internal.CompatPrim@@ -43,10 +48,17 @@ (==) = scrubbedBytesEq instance Ord ScrubbedBytes where compare = scrubbedBytesCompare+#if MIN_VERSION_base(4,9,0)+instance Semigroup ScrubbedBytes where+ b1 <> b2 = unsafeDoIO $ scrubbedBytesAppend b1 b2+ sconcat = unsafeDoIO . scrubbedBytesConcat . toList+#endif instance Monoid ScrubbedBytes where mempty = unsafeDoIO (newScrubbedBytes 0)+#if !(MIN_VERSION_base(4,11,0)) mappend b1 b2 = unsafeDoIO $ scrubbedBytesAppend b1 b2 mconcat = unsafeDoIO . scrubbedBytesConcat+#endif instance NFData ScrubbedBytes where rnf b = b `seq` () instance IsString ScrubbedBytes where
Data/ByteArray/Types.hs view
@@ -14,20 +14,20 @@ import Foreign.Ptr import Data.Monoid+import Data.Proxy+import Data.Word #ifdef WITH_BYTESTRING_SUPPORT import qualified Data.ByteString as B (length) import qualified Data.ByteString.Internal as B import Foreign.ForeignPtr (withForeignPtr) #endif-#ifdef WITH_FOUNDATION_SUPPORT-import qualified Foundation as F-import qualified Foundation.Collection as F-import qualified Foundation.String as F (toBytes, Encoding(UTF8))-import qualified Foundation.Array.Internal as F-import qualified Foundation.Primitive as F (primSizeInBytes)-#endif +import qualified Basement.Types.OffsetSize as F+import qualified Basement.UArray as F+import qualified Basement.String as F (String, toBytes, Encoding(UTF8))+import qualified Basement.PrimType as F (primSizeInBytes)+ -- | Class to Access size properties and data of a ByteArray class ByteArrayAccess ba where -- | Return the length in bytes of a bytearray@@ -56,24 +56,15 @@ return (r, B.PS fptr 0 sz) #endif -#ifdef WITH_FOUNDATION_SUPPORT-uarrayRecastW8 :: F.PrimType ty => F.UArray ty -> F.UArray F.Word8+uarrayRecastW8 :: F.PrimType ty => F.UArray ty -> F.UArray Word8 uarrayRecastW8 = F.recast instance F.PrimType ty => ByteArrayAccess (F.UArray ty) where-#if MIN_VERSION_foundation(0,0,10) length a = let F.CountOf i = F.length (uarrayRecastW8 a) in i-#else- length = F.length . uarrayRecastW8-#endif withByteArray a f = F.withPtr (uarrayRecastW8 a) (f . castPtr) instance ByteArrayAccess F.String where-#if MIN_VERSION_foundation(0,0,10) length str = let F.CountOf i = F.length bytes in i-#else- length str = F.length bytes-#endif where -- the Foundation's length return a number of elements not a number of -- bytes. For @ByteArrayAccess@, because we are using an @Int@, we@@ -83,24 +74,14 @@ instance (Ord ty, F.PrimType ty) => ByteArray (F.UArray ty) where allocRet sz f = do- mba <- F.new $ sizeRecastBytes sz F.Proxy+ mba <- F.new $ sizeRecastBytes sz Proxy a <- F.withMutablePtr mba (f . castPtr) ba <- F.unsafeFreeze mba return (a, ba) where-#if MIN_VERSION_foundation(0,0,10)- sizeRecastBytes :: F.PrimType ty => Int -> F.Proxy ty -> F.CountOf ty+ sizeRecastBytes :: F.PrimType ty => Int -> Proxy ty -> F.CountOf ty sizeRecastBytes w p = F.CountOf $ let (q,r) = w `Prelude.quotRem` szTy in q + (if r == 0 then 0 else 1) where !(F.CountOf szTy) = F.primSizeInBytes p {-# INLINE [1] sizeRecastBytes #-}-#else- sizeRecastBytes :: F.PrimType ty => Int -> F.Proxy ty -> F.Size ty- sizeRecastBytes w p = F.Size $- let (q,r) = w `Prelude.quotRem` szTy- in q + (if r == 0 then 0 else 1)- where !(F.Size szTy) = F.primSizeInBytes p- {-# INLINE [1] sizeRecastBytes #-}-#endif-#endif
memory.cabal view
@@ -1,5 +1,5 @@ Name: memory-version: 0.14.8+version: 0.14.9 Synopsis: memory and related abstraction stuff Description: Chunk of memory, polymorphic byte array management and manipulation@@ -37,11 +37,6 @@ Default: True Manual: True -Flag support_foundation- Description: add support for foundation strings and unboxed array- Default: True- Manual: True- Flag support_deepseq Description: add deepseq instances for memory types Default: True@@ -77,6 +72,7 @@ Data.ByteArray.View Build-depends: base >= 4 && < 5 , ghc-prim+ , basement -- FIXME armel or mispel is also little endian. -- might be a good idea to also add a runtime autodetect mode. -- ARCH_ENDIAN_UNKNOWN@@ -94,9 +90,6 @@ if flag(support_deepseq) CPP-options: -DWITH_DEEPSEQ_SUPPORT Build-depends: deepseq >= 1.1- if flag(support_foundation)- CPP-options: -DWITH_FOUNDATION_SUPPORT- Build-depends: foundation >= 0.0.8 ghc-options: -Wall -fwarn-tabs default-language: Haskell2010@@ -115,6 +108,3 @@ , memory ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures -threaded default-language: Haskell2010- if flag(support_foundation)- CPP-options: -DWITH_FOUNDATION_SUPPORT- Build-depends: foundation >= 0.0.8