on master help sign in
Inline the construction of a HashMap when parsing an Object

This improves performance and memory usage by about 5%.

commit96d070dea871c6ad13aba7f1b33e5abe3c891765 authorBryan O'Sullivan <bos@serpentine.com> dateFri 10 Jul 2015, 14:46 (11 years ago) parent9f2062c
1 file changed+13−1
Data/Aeson/Parser/Internal.hs+13−1
Data/Aeson/Parser/Internal.hs+13−1
@@ -113,7 +113,19 @@ objectValues :: Parser Text -> Parser Value -> Parser (H.HashMap Text Value)
113113objectValues str val = do
114114 skipSpace
115115 let pair = liftA2 (,) (str <* skipSpace) (char ':' *> val)
116− H.fromList <$> commaSeparated pair CLOSE_CURLY
116+ w <- A.peekWord8'
117+ if w == CLOSE_CURLY
118+ then A.anyWord8 >> return H.empty
119+ else loop H.empty
120+ where
121+ loop m0 = do
122+ k <- str <* skipSpace <* char ':'
123+ v <- val <* skipSpace
124+ let !m = H.insert k v m0
125+ ch <- A.satisfy $ \w -> w == COMMA || w == CLOSE_CURLY
126+ if ch == COMMA
127+ then skipSpace >> loop m
128+ else return m
117129{-# INLINE objectValues #-}
118130
119131array_ :: Parser Value