Skip to content

Commit

Permalink
Fix rewrite of reversePoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chreekat committed Sep 16, 2023
1 parent b68b460 commit 1db3735
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Data/Text/Internal/Reverse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ reverse (Text ba off len) = runST $ do
result <- A.unsafeFreeze dest
pure $ Text result 0 len

reversePoints :: A.Array -> Int -> A.MArray s -> Int -> ST s ()
reversePoints
:: A.Array -- ^ Input array
-> Int -- ^ Input index
-> A.MArray s -- ^ Output array
-> Int -- ^ Output index
-> ST s ()
reversePoints _ _ _ p_out | p_out < 0 = pure ()
reversePoints ba p_in dest p_out =
let pointLength = utf8LengthByLeader (A.unsafeIndex ba p_in)
in do
A.copyI pointLength dest (p_out - pointLength + 1) ba p_in
if p_out - pointLength >= 0
then reversePoints' ba (p_in + pointLength) dest (p_out - pointLength)
else pure ()
reversePoints ba (p_in + pointLength) dest (p_out - pointLength)
#else
reverse (Text (A.ByteArray ba) off len) = runST $ do
marr@(A.MutableByteArray mba) <- A.new len
Expand Down

0 comments on commit 1db3735

Please sign in to comment.