@@ -57,6 +57,7 @@ import Control.DeepSeq (NFData(..))
5757import Control.Monad.State.Strict
5858import Data.Aeson.Functions
5959import Data.Attoparsec.Char8 (Number(..))
60+import Data.Bits (shiftR)
6061import Data.Data (Data)
6162import Data.Hashable (Hashable(..))
6263import Data.Int (Int8, Int16, Int32, Int64)
@@ -1043,7 +1044,7 @@ instance (ConsFromJSON a) => GFromJSON (C1 c a) where
10431044instance ( GFromProduct a, GFromProduct b
10441045 , ProductSize a, ProductSize b) => GFromJSON (a :*: b) where
10451046 gParseJSON (Array arr)
1046− | lenArray == lenProduct = gParseProduct arr
1047+ | lenArray == lenProduct = gParseProduct arr 0 lenProduct
10471048 | otherwise =
10481049 fail $ "When expecting a product of " ++ show lenProduct ++
10491050 " values, encountered an Array of " ++ show lenArray ++
@@ -1114,16 +1115,19 @@ instance ProductSize (S1 s a) where
11141115--------------------------------------------------------------------------------
11151116
11161117class GFromProduct f where
1117− gParseProduct :: Array -> Parser (f a)
1118+ gParseProduct :: Array -> Int -> Int -> Parser (f a)
11181119
11191120instance (GFromProduct a, GFromProduct b) => GFromProduct (a :*: b) where
1120− gParseProduct arr = (:*:) <$> gParseProduct arrL <*> gParseProduct arrR
1121+ gParseProduct arr ix len = (:*:) <$> gParseProduct arr ix lenL
1122+ <*> gParseProduct arr ixR lenR
11211123 where
1122− (arrL, arrR) = V.splitAt (V.length arr `div` 2) arr
1124+ lenL = len `shiftR` 1
1125+ ixR = ix + lenL
1126+ lenR = len - lenL
11231127 {-# INLINE gParseProduct #-}
11241128
11251129instance (GFromJSON a) => GFromProduct (S1 s a) where
1126− gParseProduct arr = gParseJSON $ V.unsafeIndex arr 0
1130+ gParseProduct arr ix _ = gParseJSON $ V.unsafeIndex arr ix
11271131 {-# INLINE gParseProduct #-}
11281132
11291133--------------------------------------------------------------------------------