on master help sign in
Use unsafeShiftL/R more often
commitf6d1e43cb7ec8b179bcd16e8b7814928762c3599 authorHerbert Valerio Riedel <hvr@gnu.org> dateSun 1 Apr 2018, 18:46 (9 years ago) parent873f25d
1 file changed+10−8
uuid-types/Data/UUID/Types/Internal.hs+10−8
uuid-types/Data/UUID/Types/Internal.hs+10−8
@@ -188,10 +188,10 @@ pack unpacked =
188188
189189-- |Build a Word32 from four Word8 values, presented in big-endian order
190190word :: Word8 -> Word8 -> Word8 -> Word8 -> Word32
191−word a b c d = (fromIntegral a `shiftL` 24)
192− .|. (fromIntegral b `shiftL` 16)
193− .|. (fromIntegral c `shiftL` 8)
194− .|. (fromIntegral d )
191+word a b c d = (fromIntegral a `unsafeShiftL` 24)
192+ .|. (fromIntegral b `unsafeShiftL` 16)
193+ .|. (fromIntegral c `unsafeShiftL` 8)
194+ .|. (fromIntegral d )
195195
196196-- |Extract a Word8 from a Word64. Bytes, high to low, are numbered from 7 to 0,
197197byte :: Int -> Word64 -> Word8
@@ -200,7 +200,7 @@ byte i w = fromIntegral (w `shiftR` (i * 8))
200200-- |Build a Word16 from two Word8 values, presented in big-endian order.
201201w8to16 :: Word8 -> Word8 -> Word16
202202w8to16 w0s w1s =
203− (w0 `shiftL` 8) .|. w1
203+ (w0 `unsafeShiftL` 8) .|. w1
204204 where
205205 w0 = fromIntegral w0s
206206 w1 = fromIntegral w1s
@@ -490,8 +490,8 @@ type instance ByteSink ThreeByte g = Takes3Bytes g
490490newtype ThreeByte = ThreeByte Int
491491instance ByteSource ThreeByte where
492492 f /-/ (ThreeByte w) = f b1 b2 b3
493− where b1 = fromIntegral (w `shiftR` 16)
494− b2 = fromIntegral (w `shiftR` 8)
493+ where b1 = fromIntegral (w `unsafeShiftR` 16)
494+ b2 = fromIntegral (w `unsafeShiftR` 8)
495495 b3 = fromIntegral w
496496
497497instance NFData UUID where
@@ -571,7 +571,9 @@ uuidType :: DataType
571571uuidType = mkNoRepType "Data.UUID.Types.UUID"
572572
573573#if !MIN_VERSION_base(4,5,0)
574−unsafeShiftR, unsafeShiftL :: Word64 -> Int -> Word64
574+unsafeShiftR, unsafeShiftL :: Bits w => w -> Int -> w
575+{-# INLINE unsafeShiftR #-}
575576unsafeShiftR = shiftR
577+{-# INLINE unsafeShiftL #-}
576578unsafeShiftL = shiftL
577579#endif