on master help sign in
Remove duplicate work from string parser
commit84ced1530c362646d42fb1f8ea347703859eedc4 authorSean <burton.seanr@gmail.com> dateWed 22 Jul 2015, 09:17 (11 years ago) parent94a4edc
3 files changed+17−16
Data/Aeson/Parser/Internal.hs+15−14 aeson.cabal+1−1 benchmarks/aeson-benchmarks.cabal+1−1
Data/Aeson/Parser/Internal.hs+15−14
@@ -203,21 +203,22 @@ jstring = A.word8 DOUBLE_QUOTE *> jstring_
203203-- | Parse a string without a leading quote.
204204jstring_ :: Parser Text
205205jstring_ = {-# SCC "jstring_" #-} do
206− s <- A.scan False $ \s c -> if s then Just False
207− else if c == DOUBLE_QUOTE
208− then Nothing
209− else Just (c == BACKSLASH)
210− _ <- A.word8 DOUBLE_QUOTE
211− s1 <- if BACKSLASH `B.elem` s
212− then case unescape s of
213− Right r -> return r
214− Left err -> fail err
215− else return s
216−
206+ (s, (_, escaped)) <- A.runScanner (False, False) go
207+ _ <- A.anyWord8
208+ s1 <- if escaped
209+ then case unescape s of
210+ Right r -> return r
211+ Left err -> fail err
212+ else return s
217213 case decodeUtf8' s1 of
218− Right r -> return r
219− Left err -> fail $ show err
220−
214+ Right r -> return r
215+ Left err -> fail $ show err
216+ where go (a, b) c
217+ | a = Just (False, b)
218+ | c == DOUBLE_QUOTE = Nothing
219+ | otherwise = let a' = c == backSlash
220+ in Just (a', a' || b)
221+ where backSlash = BACKSLASH
221222{-# INLINE jstring_ #-}
222223
223224unescape :: ByteString -> Either String ByteString
aeson.cabal+1−1
@@ -84,7 +84,7 @@ library
8484 Data.Aeson.Types.Internal
8585
8686 build-depends:
87− attoparsec >= 0.13.0.0,
87+ attoparsec >= 0.13.0.1,
8888 base >= 4.5 && < 5,
8989 bytestring >= 0.10.4.0,
9090 containers,
benchmarks/aeson-benchmarks.cabal+1−1
@@ -32,7 +32,7 @@ library
3232 Data.Aeson.Types.Internal
3333
3434 build-depends:
35− attoparsec >= 0.13.0.0,
35+ attoparsec >= 0.13.0.1,
3636 base == 4.*,
3737 bytestring >= 0.10.4.0,
3838 containers,