Skip to content

Changes Array to List for better performance #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Text/Parsing/Parser/Token.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Data.Functor
import Data.Identity
import Data.Int
import Data.List (List(..))
import Data.List (many, toUnfoldable) as List
import Data.Maybe
import Data.Tuple

Expand Down Expand Up @@ -397,13 +398,12 @@ makeTokenParser (LanguageDef languageDef)
where
go :: ParserT String m String
go = do
maybeCharArray <- between (char '"') (char '"' <?> "end of string") (Array.many stringChar)
pure $ fromCharArray $ foldr folder [] maybeCharArray
maybeChars <- between (char '"') (char '"' <?> "end of string") (List.many stringChar)
pure $ fromCharArray $ List.toUnfoldable $ foldr folder Nil maybeChars

folder :: Maybe Char -> Array Char -> Array Char
folder Nothing charArray = charArray
-- TODO: This is O(n).
folder (Just c) charArray = Array.cons c charArray
folder :: Maybe Char -> List Char -> List Char
folder Nothing chars = chars
folder (Just c) chars = Cons c chars


stringChar :: ParserT String m (Maybe Char)
Expand Down