packages feed

mutable-containers 0.2.1.1 → 0.2.1.2

raw patch · 3 files changed

+30/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.1.2++* `Deque` optimizations by avoiding modulus operations completely.+ ## 0.2.1.1  * Fix a bug in `Deque`'s new vector allocation/copy code.
Data/Mutable/Deque.hs view
@@ -10,6 +10,7 @@     , module Data.Mutable.Class     ) where +import           Control.Exception            (assert) import           Control.Monad                (liftM) import           Data.Mutable.Class import qualified Data.Vector.Generic.Mutable  as V@@ -75,8 +76,12 @@         if size == 0             then return Nothing             else do-                x <- V.unsafeRead v (start `mod` V.length v)-                writeRef var $! DequeState v (start + 1) (size - 1)+                x <- V.unsafeRead v start+                let start' = start + 1+                    start''+                        | start' >= V.length v = 0+                        | otherwise = start'+                writeRef var $! DequeState v start'' (size - 1)                 return $! Just x     {-# INLINE popFront #-} instance V.MVector v a => MutablePopBack (Deque v s a) where@@ -86,8 +91,11 @@             then return Nothing             else do                 let size' = size - 1-                    end = (start + size') `mod` V.length v-                x <- V.unsafeRead v end+                    end = start + size'+                    end'+                        | end >= V.length v = end - V.length v+                        | otherwise = end+                x <- V.unsafeRead v end'                 writeRef var $! DequeState v start size'                 return $! Just x     {-# INLINE popBack #-}@@ -101,9 +109,12 @@                 then newVector v start size inner                 else do                     let size' = size + 1-                        start' = (start - 1) `mod` V.length v-                    V.unsafeWrite v start' x-                    writeRef var $! DequeState v start' size'+                        start' = (start - 1) `rem` V.length v+                        start''+                            | start' < 0 = V.length v + start'+                            | otherwise = start'+                    V.unsafeWrite v start'' x+                    writeRef var $! DequeState v start'' size'     {-# INLINE pushFront #-} instance V.MVector v a => MutablePushBack (Deque v s a) where     pushBack (Deque var) x = do@@ -114,8 +125,11 @@             if size >= V.length v                 then newVector v start size inner                 else do-                    let end = (start + size) `mod` V.length v-                    V.unsafeWrite v end x+                    let end = start + size+                        end'+                            | end >= V.length v = end - V.length v+                            | otherwise = end+                    V.unsafeWrite v end' x                     writeRef var $! DequeState v start (size + 1)     {-# INLINE pushBack #-} @@ -125,15 +139,14 @@           -> Int           -> (v (PrimState m) a -> Int -> Int -> m b)           -> m b-newVector v start size f = do+newVector v size2 sizeOrig f = assert (sizeOrig == V.length v) $ do     v' <- V.unsafeNew (V.length v * 2)     let size1 = V.length v - size2-        size2 = start `mod` V.length v     V.unsafeCopy         (V.unsafeTake size1 v')         (V.unsafeSlice size2 size1 v)     V.unsafeCopy         (V.unsafeSlice size1 size2 v')         (V.unsafeTake size2 v)-    f v' 0 size+    f v' 0 sizeOrig {-# INLINE newVector #-}
mutable-containers.cabal view
@@ -1,5 +1,5 @@ name:                mutable-containers-version:             0.2.1.1+version:             0.2.1.2 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