on master help sign in
Turn on use of array lengths only if ASSERTS

--HG-- extra : convert_revision : ffed9f6d894f5d22c79465383a9226bf927c01ec

commit8111ffba4d7b7deb33b18ff8beb5b564cbd8dd2c authorBryan O'Sullivan <bos@serpentine.com> dateSun 29 Aug 2010, 06:44 (16 years ago) parenta828357
1 file changed+16−2
Data/Text/Array.hs+16−2
Data/Text/Array.hs+16−2
@@ -69,15 +69,20 @@ import Prelude hiding (length, read)
6969-- | Immutable array type.
7070data Array = Array {
7171 aBA :: ByteArray#
72+#if defined(ASSERTS)
7273 , aLen :: {-# UNPACK #-} !Int -- length (in units of Word16, not bytes)
74+#endif
7375 }
7476
7577-- | Mutable array type, for use in the ST monad.
7678data MArray s = MArray {
7779 maBA :: MutableByteArray# s
80+#if defined(ASSERTS)
7881 , maLen :: {-# UNPACK #-} !Int -- length (in units of Word16, not bytes)
82+#endif
7983 }
8084
85+#if defined(ASSERTS)
8186-- | Operations supported by all arrays.
8287class IArray a where
8388 -- | Return the length of an array.
@@ -90,6 +95,7 @@ instance IArray Array where
9095instance IArray (MArray s) where
9196 length = maLen
9297 {-# INLINE length #-}
98+#endif
9399
94100-- | Create an uninitialized mutable array.
95101unsafeNew :: forall s. Int -> ST s (MArray s)
@@ -104,13 +110,21 @@ unsafeNew n =
104110 if len < 0 then error (show ("unsafeNew",len)) else
105111#endif
106112 case newByteArray# len# s1# of
107− (# s2#, marr# #) -> (# s2#, MArray marr# n #)
113+ (# s2#, marr# #) -> (# s2#, MArray marr#
114+#if defined(ASSERTS)
115+ n
116+#endif
117+ #)
108118{-# INLINE unsafeNew #-}
109119
110120-- | Freeze a mutable array. Do not mutate the 'MArray' afterwards!
111121unsafeFreeze :: MArray s -> ST s Array
112122unsafeFreeze MArray{..} = ST $ \s# ->
113− (# s#, Array (unsafeCoerce# maBA) maLen #)
123+ (# s#, Array (unsafeCoerce# maBA)
124+#if defined(ASSERTS)
125+ maLen
126+#endif
127+ #)
114128{-# INLINE unsafeFreeze #-}
115129
116130-- | Indicate how many bytes would be used for an array of the given