Skip to content

Commit 5957128

Browse files
committed
inline recordParseJSONImpl
1 parent 66d68f5 commit 5957128

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/Data/Aeson/Types/FromJSON.hs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,28 +1440,18 @@ instance ( RecordFromJSON' arity a
14401440
{-# INLINE recordParseJSON' #-}
14411441

14421442
instance (Selector s, GFromJSON arity a, GOmitFromJSON arity a) => RecordFromJSON' arity (S1 s a) where
1443-
recordParseJSON' args@(_ :* _ :* opts :* fargs) obj =
1444-
recordParseJSONImpl (guard (allowOmittedFields opts) >> gOmittedField fargs) gParseJSON args obj
1445-
{-# INLINE recordParseJSON' #-}
1446-
1447-
1448-
recordParseJSONImpl :: forall s arity a f i
1449-
. (Selector s)
1450-
=> Maybe (f a)
1451-
-> (Options -> FromArgs arity a -> Value -> Parser (f a))
1452-
-> (ConName :* TypeName :* Options :* FromArgs arity a)
1453-
-> Object -> Parser (M1 i s f a)
1454-
recordParseJSONImpl mdef parseVal (cname :* tname :* opts :* fargs) obj =
1455-
handleMissingKey (M1 <$> mdef) $ do
1456-
fv <- contextCons cname tname (obj .: label)
1457-
M1 <$> parseVal opts fargs fv <?> Key label
1458-
where
1459-
handleMissingKey Nothing p = p
1460-
handleMissingKey (Just def) p = if label `KM.member` obj then p else pure def
1443+
recordParseJSON' (cname :* tname :* opts :* fargs) obj =
1444+
handleMissingKey (M1 <$> mdef) $ do
1445+
fv <- contextCons cname tname (obj .: label)
1446+
M1 <$> gParseJSON opts fargs fv <?> Key label
1447+
where
1448+
handleMissingKey Nothing p = p
1449+
handleMissingKey (Just def) p = if label `KM.member` obj then p else pure def
14611450

1462-
label = Key.fromString $ fieldLabelModifier opts sname
1463-
sname = selName (undefined :: M1 _i s _f _p)
1464-
{-# INLINE recordParseJSONImpl #-}
1451+
label = Key.fromString $ fieldLabelModifier opts sname
1452+
sname = selName (undefined :: M1 _i s _f _p)
1453+
mdef = guard (allowOmittedFields opts) >> gOmittedField fargs
1454+
{-# INLINE recordParseJSON' #-}
14651455

14661456
--------------------------------------------------------------------------------
14671457

0 commit comments

Comments
 (0)