Revert the Foreign.getIndex order change as it is a released API

This commit is contained in:
Adithya Kumar 2022-02-06 00:55:53 +05:30
parent 7cd7a185d3
commit f235118945
3 changed files with 7 additions and 5 deletions

View File

@ -85,7 +85,7 @@ toChunksLast inh = do
larr <- Stream.last s
return $ case larr of
Nothing -> Nothing
Just arr -> Array.getIndex (Array.length arr - 1) arr
Just arr -> Array.getIndex arr (Array.length arr - 1)
#ifdef INSPECTION
inspect $ hasNoTypeClasses 'toChunksLast

View File

@ -427,12 +427,14 @@ getSlicesFromLen from len =
-- XXX Change this to a partial function instead of a Maybe type? And use
-- MA.getIndex instead.
--
-- XXX The signature should be "Int -> Array a -> Maybe a"
-- XXX This is a released API so make this change in the next major release.
-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
--
-- @since 0.8.0
{-# INLINE getIndex #-}
getIndex :: forall a. Storable a => Int -> Array a -> Maybe a
getIndex i arr =
getIndex :: forall a. Storable a => Array a -> Int -> Maybe a
getIndex arr i =
unsafeInlineIO
$ MA.unsafeWithArrayContents (arrContents arr) (arrStart arr)
$ \ptr -> do

View File

@ -658,7 +658,7 @@ ensureTrailingSlash :: Array Word8 -> Array Word8
ensureTrailingSlash path =
if byteLength path /= 0
then
let mx = A.getIndex (byteLength path - 1) path
let mx = A.getIndex path (byteLength path - 1)
in case mx of
Nothing -> error "ensureTrailingSlash: Bug: Invalid index"
Just x ->
@ -672,7 +672,7 @@ removeTrailingSlash path =
if byteLength path /= 0
then
let n = byteLength path - 1
mx = A.getIndex n path
mx = A.getIndex path n
in case mx of
Nothing -> error "removeTrailingSlash: Bug: Invalid index"
Just x ->