@@ -236,22 +236,18 @@ groupEquivalentStates dfa = outerLoop ([], initialSubsets dfa)
236236 guard $ not $ IntSet. null x
237237 pure x
238238
239- -- Given X, refine values in R, refine values in W, and finally combine the
240- -- results to obtain the new values of R an W.
241- -- We can do both steps in parallel, since the new sets to add to W we find
242- -- while processing R have already been refined by X; it is therefore fine
243- -- to only refine the original states in W.
239+ -- Given X, refine values in R, then refine values in W, building
240+ -- the new values of R and W along the way.
244241 refineWithX (r, w) x =
245- let (r', w') = unzip $ map (processR x) r
246- w'' = concatMap (processW x) w
247- in (concat r', concat w' ++ w'')
242+ let (r', w') = List. foldl' (processR x) ([] , [] ) r
243+ in (r', List. foldl' (processW x) w' w)
248244
249- processR x y = case refine x y of
250- Nothing -> ([y], [] )
245+ processR x (r', w') y = case refine x y of
246+ Nothing -> (y : r', w' )
251247 Just (y1, y2)
252- | IntSet. size y1 <= IntSet. size y2 -> ([y2], [y1] )
253- | otherwise -> ([y1], [y2] )
248+ | IntSet. size y1 <= IntSet. size y2 -> (y2 : r', y1 : w' )
249+ | otherwise -> (y1 : r', y2 : w' )
254250
255- processW x y = case refine x y of
256- Nothing -> [y]
257- Just (y1, y2) -> [y1, y2]
251+ processW x w' y = case refine x y of
252+ Nothing -> y : w'
253+ Just (y1, y2) -> y1 : y2 : w'
0 commit comments