on master help sign in
Fix a bug in "resize"

With the bug it would always reallocate even if there is spare capacity in the array.

commit9d17f13977849dffee4607650d14e2f9ebd3096a authorHarendra Kumar <harendra@composewell.com> dateThu 4 Jan 2024, 15:09 (3 years ago) parent0833f53
1 file changed+4−6
core/src/Streamly/Internal/Data/MutArray/Type.hs+4−6
core/src/Streamly/Internal/Data/MutArray/Type.hs+4−6
@@ -874,9 +874,8 @@ resize :: forall m a. (MonadIO m, Unbox a) =>
874874 Int -> MutArray a -> m (MutArray a)
875875resize nElems arr@MutArray{..} = do
876876 let req = SIZE_OF(a) * nElems
877− -- XXX Should use arrBound
878− len = arrEnd - arrStart
879− if req < len
877+ cap = arrBound - arrStart
878+ if req < cap
880879 then return arr
881880 else realloc req arr
882881
@@ -893,9 +892,8 @@ resizeExp nElems arr@MutArray{..} = do
893892 if req > largeObjectThreshold
894893 then roundUpToPower2 req
895894 else req
896− -- XXX Should use arrBound
897− len = arrEnd - arrStart
898− if req1 < len
895+ cap = arrBound - arrStart
896+ if req1 < cap
899897 then return arr
900898 else realloc req1 arr
901899