on master help sign in
Fix GHC warnings
ed53a4bSylvain HENRY
Data/Binary/Bits/Get.hs+28−21
@@ -87,7 +87,7 @@ module Data.Binary.Bits.Get
87
87
88 ) where
88 ) where
89
89
90−import Data.Binary.Get as B ( runGet, Get, getByteString, getLazyByteString, isEmpty )
90+import Data.Binary.Get as B ( Get, getLazyByteString, isEmpty )
91import Data.Binary.Get.Internal as B ( get, put, ensureN )
91import Data.Binary.Get.Internal as B ( get, put, ensureN )
92
92
93import Data.ByteString as B
93import Data.ByteString as B
@@ -222,11 +222,13 @@ readWord8 n (S bs o)
222
222
223 -- the bits are in two different bytes
223 -- the bits are in two different bytes
224 -- make a word16 using both bytes, and then shift and mask
224 -- make a word16 using both bytes, and then shift and mask
225+ -- n <= 8
226+ | otherwise = let
225− | n <= 8 = let w = (fromIntegral (unsafeHead bs) `shiftl_w16` 8) .|.
227+ w = (fromIntegral (unsafeHead bs) `shiftl_w16` 8) .|.
226− (fromIntegral (unsafeIndex bs 1))
228+ (fromIntegral (unsafeIndex bs 1))
227− m = make_mask n
229+ m = make_mask n
228− w' = (w `shiftr_w16` (16 - o - n)) .&. m
230+ w' = (w `shiftr_w16` (16 - o - n)) .&. m
229− in fromIntegral w'
231+ in fromIntegral w'
230
232
231{-# INLINE readWord16be #-}
233{-# INLINE readWord16be #-}
232readWord16be :: Int -> S -> Word16
234readWord16be :: Int -> S -> Word16
@@ -301,22 +303,23 @@ readWithoutOffset (S bs o) shifterL shifterR n
301 | bit_offset n == 0 && byte_offset n <= 4 =
303 | bit_offset n == 0 && byte_offset n <= 4 =
302 let segs = byte_offset n
304 let segs = byte_offset n
303 bn 0 = fromIntegral (unsafeHead bs)
305 bn 0 = fromIntegral (unsafeHead bs)
304− bn n = (bn (n-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs n)
306+ bn m = (bn (m-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs m)
305
307
306 in bn (segs-1)
308 in bn (segs-1)
307
309
310+ -- n <= 64
308− | n <= 64 = let segs = byte_offset n
311+ | otherwise = let segs = byte_offset n
309− o' = bit_offset (n - 8 + o)
312+ o' = bit_offset (n - 8 + o)
310
313
311− bn 0 = fromIntegral (unsafeHead bs)
314+ bn 0 = fromIntegral (unsafeHead bs)
312− bn n = (bn (n-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs n)
315+ bn m = (bn (m-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs m)
313
316
314− msegs = bn (segs-1) `shifterL` o'
317+ msegs = bn (segs-1) `shifterL` o'
315
318
316− last = (fromIntegral (unsafeIndex bs segs)) `shifterR` (8 - o')
319+ lst = (fromIntegral (unsafeIndex bs segs)) `shifterR` (8 - o')
317
320
318− w = msegs .|. last
321+ w = msegs .|. lst
319− in w
322+ in w
320
323
321readWithOffset :: (Bits a, Num a)
324readWithOffset :: (Bits a, Num a)
322 => S -> (a -> Int -> a) -> (a -> Int -> a) -> Int -> a
325 => S -> (a -> Int -> a) -> (a -> Int -> a) -> Int -> a
@@ -328,17 +331,18 @@ readWithOffset (S bs o) shifterL shifterR n
328 segs = byte_offset n'
331 segs = byte_offset n'
329
332
330 bn 0 = 0
333 bn 0 = 0
331− bn n = (bn (n-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs n)
334+ bn m = (bn (m-1) `shifterL` 8) .|. fromIntegral (unsafeIndex bs m)
332
335
333 o' = bit_offset n'
336 o' = bit_offset n'
334
337
335 mseg = bn segs `shifterL` o'
338 mseg = bn segs `shifterL` o'
336
339
337− last | o' > 0 = (fromIntegral (unsafeIndex bs (segs + 1))) `shifterR` (8 - o')
340+ lst | o' > 0 = (fromIntegral (unsafeIndex bs (segs + 1))) `shifterR` (8 - o')
338− | otherwise = 0
341+ | otherwise = 0
339
342
340− w = top .|. mseg .|. last
343+ w = top .|. mseg .|. lst
341 in w
344 in w
345+ | otherwise = error $ "Invalid offset (" ++ show n ++ " > 64)"
342
346
343------------------------------------------------------------------------
347------------------------------------------------------------------------
344-- | 'BitGet' is a monad, applicative and a functor. See 'runBitGet'
348-- | 'BitGet' is a monad, applicative and a functor. See 'runBitGet'
@@ -485,8 +489,12 @@ shiftl_w16 :: Word16 -> Int -> Word16
485shiftl_w32 :: Word32 -> Int -> Word32
489shiftl_w32 :: Word32 -> Int -> Word32
486shiftl_w64 :: Word64 -> Int -> Word64
490shiftl_w64 :: Word64 -> Int -> Word64
487
491
492+shiftr_w8 :: Word8 -> Int -> Word8
493+shiftr_w16 :: Word16 -> Int -> Word16
494+shiftr_w32 :: Word32 -> Int -> Word32
495+shiftr_w64 :: Word64 -> Int -> Word64
496+
488#if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__)
497#if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__)
489−shiftl_w8 (W8# w) (I# i) = W8# (w `uncheckedShiftL#` i)
490shiftl_w16 (W16# w) (I# i) = W16# (w `uncheckedShiftL#` i)
498shiftl_w16 (W16# w) (I# i) = W16# (w `uncheckedShiftL#` i)
491shiftl_w32 (W32# w) (I# i) = W32# (w `uncheckedShiftL#` i)
499shiftl_w32 (W32# w) (I# i) = W32# (w `uncheckedShiftL#` i)
492
500
@@ -513,7 +521,6 @@ shiftr_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftRL#` i)
513#endif
521#endif
514
522
515#else
523#else
516−shiftl_w8 = shiftL
517shiftl_w16 = shiftL
524shiftl_w16 = shiftL
518shiftl_w32 = shiftL
525shiftl_w32 = shiftL
519shiftl_w64 = shiftL
526shiftl_w64 = shiftL