on master help sign in
20% win on String encoding, after much mental torture
commitbc3a419467d652252322bccec918901f3b41e93a authorBryan O'Sullivan <bos@serpentine.com> dateMon 6 Jul 2015, 20:46 (11 years ago) parent7a32812
1 file changed+2−4
Data/Aeson/Encode/Builder.hs+2−4
Data/Aeson/Encode/Builder.hs+2−4
@@ -93,10 +93,8 @@ unquoted t = TE.encodeUtf8BuilderEscaped escapeAscii t
9393
9494-- | Encode a JSON string.
9595string :: String -> Builder
96−string t = B.char8 '"' <> foldMap go t <> B.char8 '"'
97− where go c | c > '\x7f' = BP.primBounded BP.charUtf8 c
98− | otherwise = BP.primBounded escapeAscii (c2w c)
99−{-# INLINE string #-}
96+string t = B.char8 '"' <> BP.primMapListBounded go t <> B.char8 '"'
97+ where go = BP.condB (> '\x7f') BP.charUtf8 (c2w >$< escapeAscii)
10098
10199escapeAscii :: BP.BoundedPrim Word8
102100escapeAscii =