on master help sign in
Assert length is multiple of elemSize
e870b5cHarendra Kumar
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+4−1
@@ -455,7 +455,10 @@ byteLength Array{..} =
455-- @since 0.7.0
455-- @since 0.7.0
456{-# INLINE length #-}
456{-# INLINE length #-}
457length :: forall a. Storable a => Array a -> Int
457length :: forall a. Storable a => Array a -> Int
458+length arr =
458−length arr = byteLength arr `div` sizeOf (undefined :: a)
459+ let elemSize = sizeOf (undefined :: a)
460+ blen = byteLength arr
461+ in assert (blen `mod` elemSize == 0) (blen `div` elemSize)
459
462
460-- | Get the total capacity of an array. An array may have space reserved
463-- | Get the total capacity of an array. An array may have space reserved
461-- beyond the current used length of the array.
464-- beyond the current used length of the array.