on master help sign in
Replace copy with partialCopyM
00722f1Bryan O'Sullivan
Data/Text/Array.hs−20
@@ -30,7 +30,6 @@ module Data.Text.Array
30 , MArray
30 , MArray
31
31
32 -- * Functions
32 -- * Functions
33− , copy
34 , partialCopyM
33 , partialCopyM
35 , partialCopyI
34 , partialCopyI
36 , empty
35 , empty
@@ -205,25 +204,6 @@ wordFactor = SIZEOF_HSWORD `shiftR` 1
205wordAligned :: Int -> Bool
204wordAligned :: Int -> Bool
206wordAligned i = i .&. (wordFactor - 1) == 0
205wordAligned i = i .&. (wordFactor - 1) == 0
207
206
208−-- | Copy an array in its entirety. The destination array must be at
209−-- least as big as the source.
210−copy :: MArray s -- ^ source array
211− -> MArray s -- ^ destination array
212− -> ST s ()
213−copy dest@(MArray _ dlen) src@(MArray _ slen)
214− | dlen >= slen = fast_loop 0
215− | otherwise = fail "Data.Text.Array.copy: array too small"
216− where
217− nwds = slen `div` wordFactor
218− fast_loop !i
219− | i >= nwds = copy_loop (i * wordFactor)
220− | otherwise = do unsafeReadWord src i >>= unsafeWriteWord dest i
221− fast_loop (i+1)
222− copy_loop !i
223− | i >= slen = return ()
224− | otherwise = do unsafeRead src i >>= unsafeWrite dest i
225− copy_loop (i+1)
226−
227-- | Copy some elements of a mutable array.
207-- | Copy some elements of a mutable array.
228partialCopyM :: MArray s -- ^ Destination
208partialCopyM :: MArray s -- ^ Destination
229 -> Int -- ^ Destination offset
209 -> Int -- ^ Destination offset
Data/Text/Fusion.hs+2−1
@@ -105,7 +105,8 @@ unstream (Stream next0 s0 len) = I.textP (P.fst a) 0 (P.snd a)
105 | j >= top -> {-# SCC "unstream/resize" #-} do
105 | j >= top -> {-# SCC "unstream/resize" #-} do
106 let top' = (top + 1) `shiftL` 1
106 let top' = (top + 1) `shiftL` 1
107 arr' <- A.unsafeNew top'
107 arr' <- A.unsafeNew top'
108+ A.partialCopyM arr' 0 arr 0 top
108− A.copy arr' arr >> outer arr' top' s i
109+ outer arr' top' s i
109 | otherwise -> do d <- unsafeWrite arr i x
110 | otherwise -> do d <- unsafeWrite arr i x
110 loop s' (i+d)
111 loop s' (i+d)
111 where j | ord x < 0x10000 = i
112 where j | ord x < 0x10000 = i
Data/Text/Lazy/Fusion.hs+1−1
@@ -67,7 +67,7 @@ unstreamChunks chunkSize (Stream next s0 len0)
67 | i + 1 >= len = do
67 | i + 1 >= len = do
68 let newLen = min (len `shiftL` 1) chunkSize
68 let newLen = min (len `shiftL` 1) chunkSize
69 marr' <- A.unsafeNew newLen
69 marr' <- A.unsafeNew newLen
70− A.copy marr' marr
70+ A.partialCopyM marr' 0 marr 0 len
71 inner marr' newLen s i
71 inner marr' newLen s i
72 | otherwise =
72 | otherwise =
73 case next s of
73 case next s of