Skip to content

Commit c910e39

Browse files
Improve performance of string (#93)
Co-authored-by: Thomas Honeyman <admin@thomashoneyman.com>
1 parent ca0234e commit c910e39

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

bower.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
"package.json"
2121
],
2222
"dependencies": {
23-
"purescript-arrays": "^5.0.0",
24-
"purescript-either": "^4.0.0",
25-
"purescript-foldable-traversable": "^4.0.0",
26-
"purescript-identity": "^4.0.0",
27-
"purescript-integers": "^4.0.0",
28-
"purescript-lists": "^5.0.0",
29-
"purescript-maybe": "^4.0.0",
30-
"purescript-strings": "^4.0.0",
31-
"purescript-transformers": "^4.1.0",
32-
"purescript-unicode": "^4.0.0",
33-
"purescript-generics-rep": "^6.1.1"
23+
"purescript-arrays": "master",
24+
"purescript-either": "master",
25+
"purescript-foldable-traversable": "master",
26+
"purescript-identity": "master",
27+
"purescript-integers": "master",
28+
"purescript-lists": "master",
29+
"purescript-maybe": "master",
30+
"purescript-strings": "master",
31+
"purescript-transformers": "master",
32+
"purescript-unicode": "master"
33+
"purescript-generics-rep": "master"
3434
},
3535
"devDependencies": {
36-
"purescript-assert": "^4.0.0",
37-
"purescript-console": "^4.1.0",
38-
"purescript-psci-support": "^4.0.0"
36+
"purescript-assert": "master",
37+
"purescript-console": "master",
38+
"purescript-psci-support": "master"
3939
}
4040
}

src/Text/Parsing/Parser/String.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Data.Array (many)
99
import Data.Foldable (elem, notElem)
1010
import Data.Maybe (Maybe(..))
1111
import Data.Newtype (wrap)
12-
import Data.String (Pattern, length)
12+
import Data.String (Pattern)
1313
import Data.String as S
1414
import Data.String.CodeUnits as SCU
1515
import Text.Parsing.Parser (ParseState(..), ParserT, fail)
@@ -20,14 +20,14 @@ import Text.Parsing.Parser.Pos (updatePosString)
2020
-- | operations which this modules needs.
2121
class StringLike s where
2222
drop :: Int -> s -> s
23-
indexOf :: Pattern -> s -> Maybe Int
23+
stripPrefix :: Pattern -> s -> Maybe s
2424
null :: s -> Boolean
2525
uncons :: s -> Maybe { head :: Char, tail :: s }
2626

2727
instance stringLikeString :: StringLike String where
2828
uncons = SCU.uncons
2929
drop = S.drop
30-
indexOf = S.indexOf
30+
stripPrefix = S.stripPrefix
3131
null = S.null
3232

3333
-- | Match end-of-file.
@@ -40,10 +40,10 @@ eof = do
4040
string :: forall s m. StringLike s => Monad m => String -> ParserT s m String
4141
string str = do
4242
input <- gets \(ParseState input _ _) -> input
43-
case indexOf (wrap str) input of
44-
Just 0 -> do
43+
case stripPrefix (wrap str) input of
44+
Just remainder -> do
4545
modify_ \(ParseState _ position _) ->
46-
ParseState (drop (length str) input)
46+
ParseState remainder
4747
(updatePosString position str)
4848
true
4949
pure str

0 commit comments

Comments
 (0)