on master help sign in
Inline the construction of a HashMap when parsing an Object
96d070dBryan O'Sullivan
Data/Aeson/Parser/Internal.hs+13−1
@@ -113,7 +113,19 @@ objectValues :: Parser Text -> Parser Value -> Parser (H.HashMap Text Value)
113objectValues str val = do
113objectValues str val = do
114 skipSpace
114 skipSpace
115 let pair = liftA2 (,) (str <* skipSpace) (char ':' *> val)
115 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
117{-# INLINE objectValues #-}
129{-# INLINE objectValues #-}
118
130
119array_ :: Parser Value
131array_ :: Parser Value