@@ -657,11 +657,13 @@ instance (ToJSON a) => ToJSON [a] where
657
657
instance OVERLAPPABLE_ (GToJSON enc arity a ) => GToJSON enc arity (M1 i c a ) where
658
658
-- Meta-information, which is not handled elsewhere, is ignored:
659
659
gToJSON opts targs = gToJSON opts targs . unM1
660
+ {-# INLINE gToJSON #-}
660
661
661
662
instance GToJSON enc One Par1 where
662
663
-- Direct occurrences of the last type parameter are encoded with the
663
664
-- function passed in as an argument:
664
665
gToJSON _opts (To1Args tj _) = tj . unPar1
666
+ {-# INLINE gToJSON #-}
665
667
666
668
instance ( ConsToJSON enc arity a
667
669
, AllNullary (C1 c a ) allNullary
@@ -674,11 +676,13 @@ instance ( ConsToJSON enc arity a
674
676
. sumToJSON opts targs
675
677
. unM1
676
678
| otherwise = consToJSON opts targs . unM1 . unM1
679
+ {-# INLINE gToJSON #-}
677
680
678
681
instance (ConsToJSON enc arity a ) => GToJSON enc arity (C1 c a ) where
679
682
-- Constructors need to be encoded differently depending on whether they're
680
683
-- a record or not. This distinction is made by 'consToJSON':
681
684
gToJSON opts targs = consToJSON opts targs . unM1
685
+ {-# INLINE gToJSON #-}
682
686
683
687
instance ( AllNullary (a :+: b ) allNullary
684
688
, SumToJSON enc arity (a :+: b ) allNullary
@@ -689,6 +693,7 @@ instance ( AllNullary (a :+: b) allNullary
689
693
-- strings. This distinction is made by 'sumToJSON':
690
694
gToJSON opts targs = (unTagged :: Tagged allNullary enc -> enc )
691
695
. sumToJSON opts targs
696
+ {-# INLINE gToJSON #-}
692
697
693
698
--------------------------------------------------------------------------------
694
699
-- Generic toJSON
@@ -700,15 +705,18 @@ instance ( AllNullary (a :+: b) allNullary
700
705
instance ToJSON a => GToJSON Value arity (K1 i a ) where
701
706
-- Constant values are encoded using their ToJSON instance:
702
707
gToJSON _opts _ = toJSON . unK1
708
+ {-# INLINE gToJSON #-}
703
709
704
710
instance ToJSON1 f => GToJSON Value One (Rec1 f ) where
705
711
-- Recursive occurrences of the last type parameter are encoded using their
706
712
-- ToJSON1 instance:
707
713
gToJSON _opts (To1Args tj tjl) = liftToJSON tj tjl . unRec1
714
+ {-# INLINE gToJSON #-}
708
715
709
716
instance GToJSON Value arity U1 where
710
717
-- Empty constructors are encoded to an empty array:
711
718
gToJSON _opts _ _ = emptyArray
719
+ {-# INLINE gToJSON #-}
712
720
713
721
instance ( WriteProduct arity a , WriteProduct arity b
714
722
, ProductSize a , ProductSize b
@@ -725,6 +733,7 @@ instance ( WriteProduct arity a, WriteProduct arity b
725
733
where
726
734
lenProduct = (unTagged2 :: Tagged2 (a :*: b ) Int -> Int )
727
735
productSize
736
+ {-# INLINE gToJSON #-}
728
737
729
738
instance ( ToJSON1 f
730
739
, GToJSON Value One g
@@ -736,22 +745,26 @@ instance ( ToJSON1 f
736
745
gToJSON opts targs =
737
746
let gtj = gToJSON opts targs in
738
747
liftToJSON gtj (listValue gtj) . unComp1
748
+ {-# INLINE gToJSON #-}
739
749
740
750
--------------------------------------------------------------------------------
741
751
-- Generic toEncoding
742
752
743
753
instance ToJSON a => GToJSON Encoding arity (K1 i a ) where
744
754
-- Constant values are encoded using their ToJSON instance:
745
755
gToJSON _opts _ = toEncoding . unK1
756
+ {-# INLINE gToJSON #-}
746
757
747
758
instance ToJSON1 f => GToJSON Encoding One (Rec1 f ) where
748
759
-- Recursive occurrences of the last type parameter are encoded using their
749
760
-- ToEncoding1 instance:
750
761
gToJSON _opts (To1Args te tel) = liftToEncoding te tel . unRec1
762
+ {-# INLINE gToJSON #-}
751
763
752
764
instance GToJSON Encoding arity U1 where
753
765
-- Empty constructors are encoded to an empty array:
754
766
gToJSON _opts _ _ = E. emptyArray_
767
+ {-# INLINE gToJSON #-}
755
768
756
769
instance ( EncodeProduct arity a
757
770
, EncodeProduct arity b
@@ -761,6 +774,7 @@ instance ( EncodeProduct arity a
761
774
-- the same size as the product and write the product's elements to it using
762
775
-- 'encodeProduct':
763
776
gToJSON opts targs p = E. list E. retagEncoding [encodeProduct opts targs p]
777
+ {-# INLINE gToJSON #-}
764
778
765
779
instance ( ToJSON1 f
766
780
, GToJSON Encoding One g
@@ -772,6 +786,7 @@ instance ( ToJSON1 f
772
786
gToJSON opts targs =
773
787
let gte = gToJSON opts targs in
774
788
liftToEncoding gte (listEncoding gte) . unComp1
789
+ {-# INLINE gToJSON #-}
775
790
776
791
--------------------------------------------------------------------------------
777
792
@@ -983,6 +998,7 @@ instance ( RecordToPairs enc pairs arity f
983
998
) => ConsToJSON' enc arity f True
984
999
where
985
1000
consToJSON' opts targs = Tagged . fromPairs . recordToPairs opts targs
1001
+ {-# INLINE consToJSON' #-}
986
1002
987
1003
instance GToJSON enc arity f => ConsToJSON' enc arity f False where
988
1004
consToJSON' opts targs = Tagged . gToJSON opts targs
@@ -1074,10 +1090,12 @@ instance ( WriteProduct arity a
1074
1090
lenL = len `unsafeShiftR` 1
1075
1091
lenR = len - lenL
1076
1092
ixR = ix + lenL
1093
+ {-# INLINE writeProduct #-}
1077
1094
1078
1095
instance OVERLAPPABLE_ (GToJSON Value arity a ) => WriteProduct arity a where
1079
1096
writeProduct opts targs mv ix _ =
1080
1097
VM. unsafeWrite mv ix . gToJSON opts targs
1098
+ {-# INLINE writeProduct #-}
1081
1099
1082
1100
--------------------------------------------------------------------------------
1083
1101
@@ -1095,9 +1113,11 @@ instance ( EncodeProduct arity a
1095
1113
encodeProduct opts targs (a :*: b) =
1096
1114
encodeProduct opts targs a >*<
1097
1115
encodeProduct opts targs b
1116
+ {-# INLINE encodeProduct #-}
1098
1117
1099
1118
instance OVERLAPPABLE_ (GToJSON Encoding arity a ) => EncodeProduct arity a where
1100
1119
encodeProduct opts targs a = E. retagEncoding $ gToJSON opts targs a
1120
+ {-# INLINE encodeProduct #-}
1101
1121
1102
1122
--------------------------------------------------------------------------------
1103
1123
0 commit comments