Optimise Digraph.postOrd, used when finding strongly connected components
authorIan Lynagh <igloo@earth.li>
Thu, 16 Aug 2007 02:15:14 +0000 (02:15 +0000)
committerIan Lynagh <igloo@earth.li>
Thu, 16 Aug 2007 02:15:14 +0000 (02:15 +0000)
compiler/utils/Digraph.lhs

index cde008a..c5c9b57 100644 (file)
@@ -323,17 +323,17 @@ preArr bnds      = tabulate bnds . preorderF
 ------------------------------------------------------------
 
 \begin{code}
---postorder :: Tree a -> [a]
-postorder (Node a ts) = postorderF ts ++ [a]
+postorder :: Tree a -> [a] -> [a]
+postorder (Node a ts) = postorderF ts . (a :)
 
-postorderF   :: Forest a -> [a]
-postorderF ts = concat (map postorder ts)
+postorderF   :: Forest a -> [a] -> [a]
+postorderF ts = foldr (.) id $ map postorder ts
 
-postOrd      :: Graph -> [Vertex]
-postOrd       = postorderF . dff
+postOrd :: Graph -> [Vertex]
+postOrd g = postorderF (dff g) []
 
-topSort      :: Graph -> [Vertex]
-topSort       = reverse . postOrd
+topSort :: Graph -> [Vertex]
+topSort = reverse . postOrd
 \end{code}