on master help sign in
Drop the hand-optimize version of jstring
606fd98Yuras Shumovich
Data/Aeson/Parser/Internal.hs+1−38
@@ -2,9 +2,6 @@
2{-# LANGUAGE CPP #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE NoImplicitPrelude #-}
3{-# LANGUAGE NoImplicitPrelude #-}
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
5−#if MIN_VERSION_ghc_prim(0,3,1)
6−{-# LANGUAGE MagicHash #-}
7−#endif
8#if __GLASGOW_HASKELL__ <= 710 && __GLASGOW_HASKELL__ >= 706
5#if __GLASGOW_HASKELL__ <= 710 && __GLASGOW_HASKELL__ >= 706
9-- Work around a compiler bug
6-- Work around a compiler bug
10{-# OPTIONS_GHC -fsimpl-tick-factor=200 #-}
7{-# OPTIONS_GHC -fsimpl-tick-factor=200 #-}
@@ -61,6 +58,7 @@ import Data.Functor.Compat (($>))
61import Data.Bits (testBit)
58import Data.Bits (testBit)
62import Data.Scientific (Scientific)
59import Data.Scientific (Scientific)
63import Data.Text (Text)
60import Data.Text (Text)
61+import qualified Data.Text.Encoding as TE
64import Data.Vector (Vector)
62import Data.Vector (Vector)
65import qualified Data.Vector as Vector (empty, fromList, fromListN, reverse)
63import qualified Data.Vector as Vector (empty, fromList, fromListN, reverse)
66import qualified Data.Attoparsec.ByteString as A
64import qualified Data.Attoparsec.ByteString as A
@@ -72,12 +70,6 @@ import qualified Data.HashMap.Strict as H
72import qualified Data.Scientific as Sci
70import qualified Data.Scientific as Sci
73import Data.Aeson.Parser.Unescape (unescapeText)
71import Data.Aeson.Parser.Unescape (unescapeText)
74
72
75−#if MIN_VERSION_ghc_prim(0,3,1)
76−import GHC.Base (Int#, (==#), isTrue#, word2Int#, orI#, andI#)
77−import GHC.Word (Word8(W8#))
78−import qualified Data.Text.Encoding as TE
79−#endif
80−
81#define BACKSLASH 92
73#define BACKSLASH 92
82#define CLOSE_CURLY 125
74#define CLOSE_CURLY 125
83#define CLOSE_SQUARE 93
75#define CLOSE_SQUARE 93
@@ -336,34 +328,6 @@ jstring_ = do
336jstringSlow :: B.ByteString -> Parser Text
328jstringSlow :: B.ByteString -> Parser Text
337{-# INLINE jstringSlow #-}
329{-# INLINE jstringSlow #-}
338jstringSlow s' = {-# SCC "jstringSlow" #-} do
330jstringSlow s' = {-# SCC "jstringSlow" #-} do
339−#if MIN_VERSION_ghc_prim(0,3,1)
340− (s, S _ escaped) <- A.runScanner startState go <* A.anyWord8
341− -- We escape only if there are
342− -- non-ascii (over 7bit) characters or backslash present.
343− --
344− -- Note: if/when text will have fast ascii -> text conversion
345− -- (e.g. uses utf8 encoding) we can have further speedup.
346− if isTrue# escaped
347− then case unescapeText (s' <> s) of
348− Right r -> return r
349− Left err -> fail $ show err
350− else return (TE.decodeUtf8 (s' <> s))
351− where
352− startState = S 0# 0#
353− go (S skip escaped) (W8# c)
354− | isTrue# skip = Just (S 0# escaped')
355− | isTrue# (w ==# 34#) = Nothing -- double quote
356− | otherwise = Just (S skip' escaped')
357− where
358− w = word2Int# c
359− skip' = w ==# 92# -- backslash
360− escaped' = escaped
361− `orI#` (w `andI#` 0x80# ==# 0x80#) -- c >= 0x80
362− `orI#` skip'
363− `orI#` (w `andI#` 0x1f# ==# w) -- c < 0x20
364−
365−data S = S Int# Int#
366−#else
367 s <- A.scan startState go <* A.anyWord8
331 s <- A.scan startState go <* A.anyWord8
368 case unescapeText (s' <> s) of
332 case unescapeText (s' <> s) of
369 Right r -> return r
333 Right r -> return r
@@ -376,7 +340,6 @@ data S = S Int# Int#
376 | otherwise = let a' = c == backslash
340 | otherwise = let a' = c == backslash
377 in Just a'
341 in Just a'
378 where backslash = BACKSLASH
342 where backslash = BACKSLASH
379−#endif
380
343
381decodeWith :: Parser Value -> (Value -> Result a) -> L.ByteString -> Maybe a
344decodeWith :: Parser Value -> (Value -> Result a) -> L.ByteString -> Maybe a
382decodeWith p to s =
345decodeWith p to s =