Commits

Bryan O'Sullivan  committed bbe7e0d

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).

  • Participants
  • Parent commits f5c15c5

Comments (0)

Files changed (1)

File Data/Aeson/Parser/Internal.hs

 arrayValues :: Parser Value -> Parser (Vector Value)
 arrayValues val = do
   skipSpace
-  vals <- ((val <* skipSpace) `sepBy` (char ',' *> skipSpace)) <* char ']'
-  return (Vector.fromList vals)
+  let loop = do
+        v <- val <* skipSpace
+        -- chr 44 == ',' && chr 93 == ']'
+        ch <- A.satisfy $ \w -> w == 44 || w == 93
+        if ch == 44
+          then skipSpace >> (v:) <$> loop
+          else return [v]
+  Vector.fromList <$> loop
 {-# INLINE arrayValues #-}
 
 -- | Parse any JSON value.  You should usually 'json' in preference to