mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
optimized Data.Binary.Get.getWord8
This commit is contained in:
@@ -416,7 +416,15 @@ getPtr n = do
|
|||||||
|
|
||||||
-- | Read a Word8 from the monad state
|
-- | Read a Word8 from the monad state
|
||||||
getWord8 :: Get Word8
|
getWord8 :: Get Word8
|
||||||
getWord8 = getPtr (sizeOf (undefined :: Word8))
|
getWord8 = do
|
||||||
|
S s ss bytes <- get
|
||||||
|
case B.uncons s of
|
||||||
|
Just (w,rest) -> do put $! S rest ss (bytes + 1)
|
||||||
|
return $! w
|
||||||
|
Nothing -> case L.uncons ss of
|
||||||
|
Just (w,rest) -> do put $! mkState rest (bytes + 1)
|
||||||
|
return $! w
|
||||||
|
Nothing -> fail "too few bytes"
|
||||||
{-# INLINE getWord8 #-}
|
{-# INLINE getWord8 #-}
|
||||||
|
|
||||||
-- | Read a Word16 in big endian format
|
-- | Read a Word16 in big endian format
|
||||||
|
|||||||
Reference in New Issue
Block a user