{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
module DataFrame.Internal.Parsing.Fast (
parseIntField,
parseIntFieldSlice,
parseIntField#,
parseDoubleField,
parseDoubleFieldSlice,
parseDoubleField#,
parseBoolField,
parseBoolFieldSlice,
parseBoolField#,
parseDateField,
parseDateFieldSlice,
isMissingField,
isMissingFieldSlice,
isMissingFieldIn,
) where
import qualified Data.ByteString as BS
import Data.Time (Day)
import GHC.Exts (Double (..), Int (..))
import DataFrame.Internal.Parsing.Fast.Double (parseDoubleField#)
import DataFrame.Internal.Parsing.Fast.Int (parseIntField#)
import DataFrame.Internal.Parsing.Fast.Token (
isMissingFieldIn,
isMissingFieldSlice,
parseBoolField#,
parseDateFieldSlice,
)
parseIntField :: BS.ByteString -> Maybe Int
parseIntField :: ByteString -> Maybe Int
parseIntField ByteString
bs = ByteString -> Int -> Int -> Maybe Int
parseIntFieldSlice ByteString
bs Int
0 (ByteString -> Int
BS.length ByteString
bs)
{-# INLINE parseIntField #-}
parseIntFieldSlice :: BS.ByteString -> Int -> Int -> Maybe Int
parseIntFieldSlice :: ByteString -> Int -> Int -> Maybe Int
parseIntFieldSlice ByteString
bs Int
start Int
end =
case ByteString -> Int -> Int -> (# Int#, Int# #)
parseIntField# ByteString
bs Int
start Int
end of
(# Int#
0#, Int#
_ #) -> Maybe Int
forall a. Maybe a
Nothing
(# Int#
_, Int#
n #) -> Int -> Maybe Int
forall a. a -> Maybe a
Just (Int# -> Int
I# Int#
n)
{-# INLINE parseIntFieldSlice #-}
parseDoubleField :: BS.ByteString -> Maybe Double
parseDoubleField :: ByteString -> Maybe Double
parseDoubleField ByteString
bs = ByteString -> Int -> Int -> Maybe Double
parseDoubleFieldSlice ByteString
bs Int
0 (ByteString -> Int
BS.length ByteString
bs)
{-# INLINE parseDoubleField #-}
parseDoubleFieldSlice :: BS.ByteString -> Int -> Int -> Maybe Double
parseDoubleFieldSlice :: ByteString -> Int -> Int -> Maybe Double
parseDoubleFieldSlice ByteString
bs Int
start Int
end =
case ByteString -> Int -> Int -> (# Int#, Double# #)
parseDoubleField# ByteString
bs Int
start Int
end of
(# Int#
0#, Double#
_ #) -> Maybe Double
forall a. Maybe a
Nothing
(# Int#
_, Double#
d #) -> Double -> Maybe Double
forall a. a -> Maybe a
Just (Double# -> Double
D# Double#
d)
{-# INLINE parseDoubleFieldSlice #-}
parseBoolField :: BS.ByteString -> Maybe Bool
parseBoolField :: ByteString -> Maybe Bool
parseBoolField ByteString
bs = ByteString -> Int -> Int -> Maybe Bool
parseBoolFieldSlice ByteString
bs Int
0 (ByteString -> Int
BS.length ByteString
bs)
{-# INLINE parseBoolField #-}
parseBoolFieldSlice :: BS.ByteString -> Int -> Int -> Maybe Bool
parseBoolFieldSlice :: ByteString -> Int -> Int -> Maybe Bool
parseBoolFieldSlice ByteString
bs Int
start Int
end =
case ByteString -> Int -> Int -> (# Int#, Int# #)
parseBoolField# ByteString
bs Int
start Int
end of
(# Int#
0#, Int#
_ #) -> Maybe Bool
forall a. Maybe a
Nothing
(# Int#
_, Int#
b #) -> Bool -> Maybe Bool
forall a. a -> Maybe a
Just (Int# -> Int
I# Int#
b Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0)
{-# INLINE parseBoolFieldSlice #-}
parseDateField :: BS.ByteString -> Maybe Day
parseDateField :: ByteString -> Maybe Day
parseDateField ByteString
bs = ByteString -> Int -> Int -> Maybe Day
parseDateFieldSlice ByteString
bs Int
0 (ByteString -> Int
BS.length ByteString
bs)
{-# INLINE parseDateField #-}
isMissingField :: BS.ByteString -> Bool
isMissingField :: ByteString -> Bool
isMissingField ByteString
bs = ByteString -> Int -> Int -> Bool
isMissingFieldSlice ByteString
bs Int
0 (ByteString -> Int
BS.length ByteString
bs)
{-# INLINE isMissingField #-}