From 7038e439597a333b0ea16c7b5665b7898700adb3 Mon Sep 17 00:00:00 2001 From: meooow25 Date: Wed, 25 Dec 2024 12:50:12 +0530 Subject: [PATCH] Be strict in the parser state Improves parseNext. parseFoldr was fine but no harm in being explicit. --- src/Regex/Internal/Parser.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Regex/Internal/Parser.hs b/src/Regex/Internal/Parser.hs index d61970c..ee11773 100644 --- a/src/Regex/Internal/Parser.hs +++ b/src/Regex/Internal/Parser.hs @@ -409,7 +409,7 @@ type Foldr f a = forall b. (a -> b -> b) -> b -> f -> b parseFoldr :: Foldr f c -> Parser c a -> f -> Maybe a parseFoldr fr = \p xs -> prepareParser p >>= fr f finishParser xs where - f c k = X.oneShot (\ps -> stepParser ps c >>= k) + f c k = X.oneShot (\ !ps -> stepParser ps c >>= k) {-# INLINE parseFoldr #-} -- | \(O(mn \log m)\). Run a parser given a \"@next@\" action. @@ -460,7 +460,7 @@ parseNext p next = case prepareParser p of Nothing -> pure Nothing Just ps -> loop ps where - loop ps = next >>= \m -> case m of + loop !ps = next >>= \m -> case m of Nothing -> pure (finishParser ps) Just c -> case stepParser ps c of Nothing -> pure Nothing