on master help sign in
Claw back some of the performance loss from the previous commit

This is why submitting a "performance improvement" with a benchmark is a good idea, I mean mandatory: the rework of jstring_ allocates 50% more memory and is 15% slower than its predecessor :-(

commitc24f9d37623b066d450358c4aa7b0535bd62b0b9 authorBryan O'Sullivan <bos@serpentine.com> dateWed 22 Jul 2015, 10:16 (11 years ago) parent84ced15
1 file changed+7−5
Data/Aeson/Parser/Internal.hs+7−5
Data/Aeson/Parser/Internal.hs+7−5
@@ -200,10 +200,12 @@ value' = do
200200jstring :: Parser Text
201201jstring = A.word8 DOUBLE_QUOTE *> jstring_
202202
203+data S = S !Bool !Bool
204+
203205-- | Parse a string without a leading quote.
204206jstring_ :: Parser Text
205207jstring_ = {-# SCC "jstring_" #-} do
206− (s, (_, escaped)) <- A.runScanner (False, False) go
208+ (s, S _ escaped) <- A.runScanner (S False False) go
207209 _ <- A.anyWord8
208210 s1 <- if escaped
209211 then case unescape s of
@@ -213,11 +215,11 @@ jstring_ = {-# SCC "jstring_" #-} do
213215 case decodeUtf8' s1 of
214216 Right r -> return r
215217 Left err -> fail $ show err
216− where go (a, b) c
217− | a = Just (False, b)
218− | c == DOUBLE_QUOTE = Nothing
218+ where go (S a b) c
219+ | a = Just (S False b)
220+ | c == DOUBLE_QUOTE = Nothing
219221 | otherwise = let a' = c == backSlash
220− in Just (a', a' || b)
222+ in Just (S a' (a' || b))
221223 where backSlash = BACKSLASH
222224{-# INLINE jstring_ #-}
223225