Skip to content

Commit

Permalink
Fixes after last review
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyl20 committed Jan 16, 2024
1 parent d0150ce commit 9418846
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Data/ByteString/Internal/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ count_occ !plast !w !count !p = do
then pure count'
else count_occ plast w count' (plusPtr p 1)

-- | Haskell equivalent of C `sbs_elem_index`
elemIndex :: ByteArray# -> Word8 -> Int -> IO Int
elemIndex !ba !w !len = pure (go 0)
where
Expand All @@ -95,10 +96,6 @@ reverseBytes !dst !src !n

-- | Note that reverse_bytes reverses at least one byte.
-- Then it loops if necessary until the destination buffer is full
--
-- Compared to the C version, we use pointer themselves as counters instead of
-- carrying around the remaining number of bytes to reverse: one less operation
-- per iteration.
reverse_bytes :: Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> IO ()
reverse_bytes orig_dst dst src = do
c <- peekByteOff src 0
Expand Down Expand Up @@ -152,8 +149,9 @@ partition !p !low !high = do
-- traverse through all elements.
-- swap element smaller than pivot at index j with leftmost element at
-- index i greater than pivot (can be itself if no greater element read yet)
let !high_is_maxbound = high == maxBound
let go !i !j
| j > high = pure (i-1)
| j > high || (high_is_maxbound && j == minBound) = pure (i-1)
| otherwise = do
jv <- peekByteOff p j
if (jv <= pivot)
Expand Down

0 comments on commit 9418846

Please sign in to comment.