on master help sign in
Simplify (and probably speed up) some code a little
8048623Bryan O'Sullivan
Data/Aeson/Generic.hs+3−4
@@ -211,7 +211,7 @@ parseJSON_generic j = generic
211 | n > 1 = construct c (V.toList js) -- no field names
211 | n > 1 = construct c (V.toList js) -- no field names
212 -- FIXME? We could allow reading an array into a constructor
212 -- FIXME? We could allow reading an array into a constructor
213 -- with field names.
213 -- with field names.
214− go _ c fs@(_:_) (Object o) = selectFields (fromJSObject o) fs >>=
214+ go _ c fs@(_:_) (Object o) = selectFields o fs >>=
215 construct c -- field names
215 construct c -- field names
216 go _ c _ jd = modFail "parseJSON" $
216 go _ c _ jd = modFail "parseJSON" $
217 "bad decodeArgs data " ++ show (c, jd)
217 "bad decodeArgs data " ++ show (c, jd)
@@ -226,11 +226,10 @@ parseJSON_generic j = generic
226 [] -> lift $ modFail "construct" "empty list"
226 [] -> lift $ modFail "construct" "empty list"
227 (j':js') -> do put js'; lift $ parseJSON j'
227 (j':js') -> do put js'; lift $ parseJSON j'
228
228
229− -- Select the named fields from a JSON object. FIXME? Should
229+ -- Select the named fields from a JSON object.
230− -- this use a map?
231 selectFields fjs = mapM sel
230 selectFields fjs = mapM sel
232 where sel f = maybe (modFail "parseJSON" $ "field does not exist " ++
231 where sel f = maybe (modFail "parseJSON" $ "field does not exist " ++
233− f) return $ lookup f fjs
232+ f) return $ Map.lookup (pack f) fjs
234
233
235 -- Count how many arguments a constructor has. The value x is
234 -- Count how many arguments a constructor has. The value x is
236 -- used to determine what type the constructor returns.
235 -- used to determine what type the constructor returns.