mutable-containers 0.2.0.1 → 0.2.1
raw patch · 4 files changed
+25/−10 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Mutable: class Prim a
+ Data.Mutable: class Storable a
+ Data.Mutable: class (Vector Vector a, MVector MVector a) => Unbox a
Files
- ChangeLog.md +5/−0
- Data/Mutable.hs +6/−0
- Data/Mutable/SRef.hs +13/−9
- mutable-containers.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,8 @@+## 0.2.1++* Export `Prim`, `Unbox` and `Storable`+* `SRef` uses `ForeignPtr` directly (slightly more efficient)+ ## 0.2.0 * Restructure under the Data.Mutable module.
Data/Mutable.hs view
@@ -47,6 +47,9 @@ , PrimMonad , PrimState , RealWorld+ , Prim+ , Unbox+ , Storable ) where import Data.Mutable.Class@@ -56,3 +59,6 @@ import Data.Mutable.BRef import Data.Mutable.Deque import Data.Mutable.DList+import Data.Vector.Unboxed (Unbox)+import Data.Primitive (Prim)+import Data.Vector.Storable (Storable)
Data/Mutable/SRef.hs view
@@ -11,15 +11,15 @@ , MutableRef (..) ) where -import Control.Monad (liftM) import Data.Mutable.Class-import qualified Data.Vector.Generic.Mutable as V-import qualified Data.Vector.Storable.Mutable as VS+import Foreign.ForeignPtr+import Foreign.Storable+import Control.Monad.Primitive -- | A storable vector reference, supporting any monad. -- -- Since 0.2.0-newtype SRef s a = SRef (VS.MVector s a)+newtype SRef s a = SRef (ForeignPtr a) -- | -- Since 0.2.0@@ -32,19 +32,23 @@ instance MutableContainer (SRef s a) where type MCState (SRef s a) = s-instance VS.Storable a => MutableRef (SRef s a) where+instance Storable a => MutableRef (SRef s a) where type RefElement (SRef s a) = a - newRef = liftM SRef . V.replicate 1+ newRef x = unsafePrimToPrim $ do+ fptr <- mallocForeignPtr+ withForeignPtr fptr $ flip poke x+ return $! SRef fptr {-# INLINE newRef#-} - readRef (SRef v) = V.unsafeRead v 0+ readRef (SRef fptr) = unsafePrimToPrim $ withForeignPtr fptr peek {-# INLINE readRef #-} - writeRef (SRef v) = V.unsafeWrite v 0+ writeRef (SRef fptr) x = unsafePrimToPrim $ withForeignPtr fptr $ flip poke x {-# INLINE writeRef #-} - modifyRef (SRef v) f = V.unsafeRead v 0 >>= V.unsafeWrite v 0 . f+ modifyRef (SRef fptr) f = unsafePrimToPrim $ withForeignPtr fptr $ \ptr ->+ peek ptr >>= poke ptr . f {-# INLINE modifyRef #-} modifyRef' = modifyRef
mutable-containers.cabal view
@@ -1,5 +1,5 @@ name: mutable-containers-version: 0.2.0.1+version: 0.2.1 synopsis: Abstactions and concrete implementations of mutable containers description: See docs and README at <http://www.stackage.org/package/mutable-containers> homepage: https://github.com/fpco/mutable-containers