on master help sign in
Rewrite arrayValues to be less combinator-driven

This gives us about a 20% performance increase when parsing an array-heavy input, such as json-data/geometry.json (gh-134).

commit94e087c4f5cfd1df7f5317d53fd20c37ac01948b authorBryan O'Sullivan <bos@serpentine.com> dateTue 26 Nov 2013, 14:19 (13 years ago) parent38abccd
1 file changed+8−2
Data/Aeson/Parser/Internal.hs+8−2
Data/Aeson/Parser/Internal.hs+8−2
@@ -121,8 +121,14 @@ array_' = {-# SCC "array_'" #-} do
121121arrayValues :: Parser Value -> Parser (Vector Value)
122122arrayValues val = do
123123 skipSpace
124− vals <- ((val <* skipSpace) `sepBy` (char ',' *> skipSpace)) <* char ']'
125− return (Vector.fromList vals)
124+ let loop = do
125+ v <- val <* skipSpace
126+ -- chr 44 == ',' && chr 93 == ']'
127+ ch <- A.satisfy $ \w -> w == 44 || w == 93
128+ if ch == 44
129+ then skipSpace >> (v:) <$> loop
130+ else return [v]
131+ Vector.fromList <$> loop
126132{-# INLINE arrayValues #-}
127133
128134-- | Parse any JSON value. You should usually 'json' in preference to