Commits

Bryan O'Sullivan committed 3a20ef2

Replace copy with partialCopyM

  • Participants
  • Parent commits 301da2e

Comments (0)

Files changed (3)

File Data/Text/Array.hs

     , MArray
 
     -- * Functions
-    , copy
     , partialCopyM
     , partialCopyI
     , empty
 wordAligned :: Int -> Bool
 wordAligned i = i .&. (wordFactor - 1) == 0
 
--- | Copy an array in its entirety. The destination array must be at
--- least as big as the source.
-copy :: MArray s     -- ^ source array
-     -> MArray s     -- ^ destination array
-     -> ST s ()
-copy dest@(MArray _ dlen) src@(MArray _ slen)
-    | dlen >= slen = fast_loop 0
-    | otherwise    = fail "Data.Text.Array.copy: array too small"
-    where
-      nwds = slen `div` wordFactor
-      fast_loop !i
-          | i >= nwds = copy_loop (i * wordFactor)
-          | otherwise = do unsafeReadWord src i >>= unsafeWriteWord dest i
-                           fast_loop (i+1)
-      copy_loop !i
-          | i >= slen = return ()
-          | otherwise = do unsafeRead src i >>= unsafeWrite dest i
-                           copy_loop (i+1)
-
 -- | Copy some elements of a mutable array.
 partialCopyM :: MArray s        -- ^ Destination
              -> Int             -- ^ Destination offset

File Data/Text/Fusion.hs

                 | j >= top  -> {-# SCC "unstream/resize" #-} do
                                let top' = (top + 1) `shiftL` 1
                                arr' <- A.unsafeNew top'
-                               A.copy arr' arr >> outer arr' top' s i
+                               A.partialCopyM arr' 0 arr 0 top
+                               outer arr' top' s i
                 | otherwise -> do d <- unsafeWrite arr i x
                                   loop s' (i+d)
                 where j | ord x < 0x10000 = i

File Data/Text/Lazy/Fusion.hs

         | i + 1 >= len       = do
             let newLen = min (len `shiftL` 1) chunkSize
             marr' <- A.unsafeNew newLen
-            A.copy marr' marr
+            A.partialCopyM marr' 0 marr 0 len
             inner marr' newLen s i
         | otherwise =
             case next s of