on master help sign in
Storable instance now goes through UnpackedUUID

The instance is faster and more correct.

commit5f00ffd5a0393d6f847e8d1b172cb2c8ee4d55f3 authorAntoine Latter <aslatter@gmail.com> dateSat 19 Oct 2013, 18:51 (13 years ago) parent8da772e
1 file changed+29−4
Data/UUID/Internal.hs+29−4
Data/UUID/Internal.hs+29−4
@@ -462,14 +462,39 @@ instance Read UUID where
462462
463463instance Storable UUID where
464464 sizeOf _ = 16
465− alignment _ = 1 -- UUIDs are stored as individual octets
465+ alignment _ = 4
466466
467467 peekByteOff p off =
468− mapM (peekByteOff p) [off..(off+15)] >>= return . fromJust . fromList
468+ pack <$>
469+ (UnpackedUUID
470+ <$> peekByteOff p off -- Word32
471+ <*> peekByteOff p (off+4) -- Word16
472+ <*> peekByteOff p (off+6) -- Word16
473+ <*> peekByteOff p (off+8) -- Word8
474+ <*> peekByteOff p (off+9) -- Word8
475+ <*> peekByteOff p (off+10) -- Word8
476+ <*> peekByteOff p (off+11) -- Word8
477+ <*> peekByteOff p (off+12) -- Word8
478+ <*> peekByteOff p (off+13) -- Word8
479+ <*> peekByteOff p (off+14) -- Word8
480+ <*> peekByteOff p (off+15) -- Word8
481+ )
469482
470483 pokeByteOff p off u =
471− sequence_ $ zipWith (pokeByteOff p) [off..] (toList u)
472−
484+ case unpack u of
485+ (UnpackedUUID x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10) ->
486+ do
487+ pokeByteOff p off x0
488+ pokeByteOff p (off+4) x1
489+ pokeByteOff p (off+6) x2
490+ pokeByteOff p (off+8) x3
491+ pokeByteOff p (off+9) x4
492+ pokeByteOff p (off+10) x5
493+ pokeByteOff p (off+11) x6
494+ pokeByteOff p (off+12) x7
495+ pokeByteOff p (off+13) x8
496+ pokeByteOff p (off+14) x9
497+ pokeByteOff p (off+15) x10
473498
474499instance Binary UUID where
475500 put (UUID w0 w1 w2 w3) =