on master help sign in
20% win on String encoding, after much mental torture
bc3a419Bryan O'Sullivan
Data/Aeson/Encode/Builder.hs+2−4
@@ -93,10 +93,8 @@ unquoted t = TE.encodeUtf8BuilderEscaped escapeAscii t
93
93
94-- | Encode a JSON string.
94-- | Encode a JSON string.
95string :: String -> Builder
95string :: String -> Builder
96−string t = B.char8 '"' <> foldMap go t <> B.char8 '"'
96+string t = B.char8 '"' <> BP.primMapListBounded go t <> B.char8 '"'
97− where go c | c > '\x7f' = BP.primBounded BP.charUtf8 c
97+ where go = BP.condB (> '\x7f') BP.charUtf8 (c2w >$< escapeAscii)
98− | otherwise = BP.primBounded escapeAscii (c2w c)
99−{-# INLINE string #-}
100
98
101escapeAscii :: BP.BoundedPrim Word8
99escapeAscii :: BP.BoundedPrim Word8
102escapeAscii =
100escapeAscii =