on master help sign in
Fix up some silly inefficient folds
commit75b2b130ac51f1081ff4fa7c116687af7b248ebd authorBryan O'Sullivan <bos@serpentine.com> dateMon 6 Jul 2015, 21:01 (11 years ago) parent395b78d
1 file changed+4−8
Data/Aeson/Types/Instances.hs+4−8
Data/Aeson/Types/Instances.hs+4−8
@@ -410,8 +410,7 @@ instance ToJSON LT.Text where
410410
411411 toEncoding t = Encoding $
412412 B.char7 '"' <>
413− LT.foldrChunks (\x xs -> E.unquoted x <> xs) mempty t <>
414− B.char7 '"'
413+ LT.foldrChunks (\x xs -> E.unquoted x <> xs) (B.char7 '"') t
415414
416415instance FromJSON LT.Text where
417416 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
@@ -449,8 +448,7 @@ encodeVector xs
449448 | VG.null xs = E.emptyArray_
450449 | otherwise = Encoding $
451450 B.char7 '[' <> builder (VG.unsafeHead xs) <>
452− VG.foldr go mempty (VG.unsafeTail xs) <>
453− B.char7 ']'
451+ VG.foldr go (B.char7 ']') (VG.unsafeTail xs)
454452 where go v b = B.char7 ',' <> builder v <> b
455453
456454instance (FromJSON a) => FromJSON (Vector a) where
@@ -524,9 +522,7 @@ encodeSet minView foldr xs =
524522 case minView xs of
525523 Nothing -> E.emptyArray_
526524 Just (m,ys) -> Encoding $
527− B.char7 '[' <> builder m <>
528− foldr go mempty ys <>
529− B.char7 ']'
525+ B.char7 '[' <> builder m <> foldr go (B.char7 ']') ys
530526 where go v b = B.char7 ',' <> builder v <> b
531527
532528instance FromJSON IntSet.IntSet where
@@ -558,7 +554,7 @@ encodeMap minViewWithKey foldrWithKey xs =
558554 Nothing -> E.emptyObject_
559555 Just ((k,v),ys) -> Encoding $
560556 B.char7 '{' <> encodeKV k v <>
561− foldrWithKey go mempty ys <> B.char7 '}'
557+ foldrWithKey go (B.char7 '}') ys
562558 where go k v b = B.char7 ',' <> encodeKV k v <> b
563559
564560encodeWithKey :: (ToJSON k, ToJSON v) =>