on master help sign in
Assert length is multiple of elemSize
commite870b5cdb7de8123938f578a3d14634842975fbd authorHarendra Kumar <harendra@composewell.com> dateSun 10 Oct 2021, 19:09 (5 years ago) parentf700973
1 file changed+4−1
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+4−1
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+4−1
@@ -455,7 +455,10 @@ byteLength Array{..} =
455455-- @since 0.7.0
456456{-# INLINE length #-}
457457length :: forall a. Storable a => Array a -> Int
458−length arr = byteLength arr `div` sizeOf (undefined :: a)
458+length arr =
459+ let elemSize = sizeOf (undefined :: a)
460+ blen = byteLength arr
461+ in assert (blen `mod` elemSize == 0) (blen `div` elemSize)
459462
460463-- | Get the total capacity of an array. An array may have space reserved
461464-- beyond the current used length of the array.