basvandijk avatar basvandijk committed 73b70e6

Added INLINE pragmas to all generic methods. This speeds up the benchmarks

Comments (0)

Files changed (1)

Data/Aeson/Types/Internal.hs

 
 instance (GToJSON a) => GToJSON (M1 i c a) where
     gToJSON = gToJSON . unM1
+    {-# INLINE gToJSON #-}
 
 instance (ToJSON a) => GToJSON (K1 i a) where
     gToJSON = toJSON . unK1
+    {-# INLINE gToJSON #-}
 
 instance GToJSON U1 where
     gToJSON _ = emptyArray
+    {-# INLINE gToJSON #-}
 
 instance (ConsToJSON a) => GToJSON (C1 c a) where
     gToJSON = consToJSON . unM1
+    {-# INLINE gToJSON #-}
 
 instance (GProductToValues a, GProductToValues b) => GToJSON (a :*: b) where
     gToJSON = toJSON . toList . gProductToValues
+    {-# INLINE gToJSON #-}
 
 instance (GObject a, GObject b) => GToJSON (a :+: b) where
     gToJSON (L1 x) = Object $ gObject x
     gToJSON (R1 x) = Object $ gObject x
+    {-# INLINE gToJSON #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (IsRecord f b, ConsToJSON' b f) => ConsToJSON f where
     consToJSON = unTagged (consToJSON' :: Tagged b (f a -> Value))
+    {-# INLINE consToJSON #-}
 
 instance (GRecordToObject f) => ConsToJSON' True f where
     consToJSON' = Tagged (Object . gRecordToObject)
+    {-# INLINE consToJSON' #-}
 
 instance GToJSON f => ConsToJSON' False f where
     consToJSON' = Tagged gToJSON
+    {-# INLINE consToJSON' #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (GRecordToObject a, GRecordToObject b) => GRecordToObject (a :*: b) where
     gRecordToObject (a :*: b) = gRecordToObject a `M.union` gRecordToObject b
+    {-# INLINE gRecordToObject #-}
 
 instance (Selector s, GToJSON a) => GRecordToObject (S1 s a) where
     gRecordToObject m1 = M.singleton (pack (selName m1)) (gToJSON (unM1 m1))
+    {-# INLINE gRecordToObject #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (GProductToValues a, GProductToValues b) => GProductToValues (a :*: b) where
     gProductToValues (a :*: b) = gProductToValues a `append` gProductToValues b
+    {-# INLINE gProductToValues #-}
 
 instance (GToJSON a) => GProductToValues a where
     gProductToValues = singleton . gToJSON
+    {-# INLINE gProductToValues #-}
 
 --------------------------------------------------------------------------------
 
 instance (GObject a, GObject b) => GObject (a :+: b) where
     gObject (L1 x) = gObject x
     gObject (R1 x) = gObject x
+    {-# INLINE gObject #-}
 
 instance (Constructor c, GToJSON a, ConsToJSON a) => GObject (C1 c a) where
     gObject m1 = M.singleton (pack (conName m1)) (gToJSON m1)
+    {-# INLINE gObject #-}
 
 --------------------------------------------------------------------------------
 -- Generic parseJSON
 
 instance (GFromJSON a) => GFromJSON (M1 i c a) where
     gParseJSON = fmap M1 . gParseJSON
+    {-# INLINE gParseJSON #-}
 
 instance (FromJSON a) => GFromJSON (K1 i a) where
     gParseJSON = fmap K1 . parseJSON
+    {-# INLINE gParseJSON #-}
 
 instance GFromJSON U1 where
     gParseJSON v
         | isEmptyArray v = pure U1
         | otherwise      = typeMismatch "unit constructor (U1)" v
+    {-# INLINE gParseJSON #-}
 
 instance (ConsFromJSON a) => GFromJSON (C1 c a) where
     gParseJSON = fmap M1 . consParseJSON
+    {-# INLINE gParseJSON #-}
 
 instance (GFromProduct a, GFromProduct b) => GFromJSON (a :*: b) where
     gParseJSON (Array arr) = gParseProduct arr
     gParseJSON v = typeMismatch "product (:*:)" v
+    {-# INLINE gParseJSON #-}
 
 instance (GFromSum a, GFromSum b) => GFromJSON (a :+: b) where
     gParseJSON (Object (M.toList -> [keyVal])) = gParseSum keyVal
     gParseJSON v = typeMismatch "sum (:+:)" v
+    {-# INLINE gParseJSON #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (IsRecord f b, ConsFromJSON' b f) => ConsFromJSON f where
     consParseJSON = unTagged (consParseJSON' :: Tagged b (Value -> Parser (f a)))
+    {-# INLINE consParseJSON #-}
 
 instance (GFromRecord f) => ConsFromJSON' True f where
     consParseJSON' = Tagged parseRecord
         where
           parseRecord (Object obj) = gParseRecord obj
           parseRecord v = typeMismatch "record (:*:)" v
+    {-# INLINE consParseJSON' #-}
 
 instance (GFromJSON f) => ConsFromJSON' False f where
     consParseJSON' = Tagged gParseJSON
+    {-# INLINE consParseJSON' #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (GFromRecord a, GFromRecord b) => GFromRecord (a :*: b) where
     gParseRecord obj = (:*:) <$> gParseRecord obj <*> gParseRecord obj
+    {-# INLINE gParseRecord #-}
 
 instance (Selector s, GFromJSON a) => GFromRecord (S1 s a) where
     gParseRecord obj = case M.lookup (T.pack key) obj of
                          Just v  -> gParseJSON v
         where
           key = selName (undefined :: t s a p)
+    {-# INLINE gParseRecord #-}
 
 --------------------------------------------------------------------------------
 
     gParseProduct arr = (:*:) <$> gParseProduct arrL <*> gParseProduct arrR
         where
           (arrL, arrR) = V.splitAt (V.length arr `div` 2) arr
+    {-# INLINE gParseProduct #-}
 
 instance (GFromJSON a) => GFromProduct a where
     gParseProduct ((!? 0) -> Just v) = gParseJSON v
     gParseProduct _ = fail "Array to small"
+    {-# INLINE gParseProduct #-}
 
 --------------------------------------------------------------------------------
 
 
 instance (GFromSum a, GFromSum b) => GFromSum (a :+: b) where
     gParseSum keyVal = (L1 <$> gParseSum keyVal) <|> (R1 <$> gParseSum keyVal)
+    {-# INLINE gParseSum #-}
 
 instance (Constructor c, GFromJSON a, ConsFromJSON a) => GFromSum (C1 c a) where
     gParseSum (key, value)
         | key == pack (conName (undefined :: t c a p)) = gParseJSON value
         | otherwise = notFound $ unpack key
+    {-# INLINE gParseSum #-}
 
 notFound :: String -> Parser a
 notFound key = fail $ "The key \"" ++ key ++ "\" was not found"
 
 toList :: DList a -> [a]
 toList = ($ [])
+{-# INLINE toList #-}
 
 singleton :: a -> DList a
 singleton = (:)
+{-# INLINE singleton #-}
 
 append :: DList a -> DList a -> DList a
 append = (.)
+{-# INLINE append #-}
 
 --------------------------------------------------------------------------------
 #endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.