[commit: packages/directory] improve-tests, improve-tests-for-real, master, tmp: More efficient getDirectoryContents (81be17f)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:37:01 UTC 2015


Repository : ssh://git@git.haskell.org/directory

On branches: improve-tests,improve-tests-for-real,master,tmp
Link       : http://ghc.haskell.org/trac/ghc/changeset/81be17f03b1a9c47c0fcd318a446a643639058d9/directory

>---------------------------------------------------------------

commit 81be17f03b1a9c47c0fcd318a446a643639058d9
Author: Michael Snoyman <michael at snoyman.com>
Date:   Tue Feb 17 10:32:21 2015 +0200

    More efficient getDirectoryContents
    
    See https://ghc.haskell.org/trac/ghc/ticket/9266


>---------------------------------------------------------------

81be17f03b1a9c47c0fcd318a446a643639058d9
 System/Directory.hs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/System/Directory.hs b/System/Directory.hs
index 26600a0..29addf1 100644
--- a/System/Directory.hs
+++ b/System/Directory.hs
@@ -839,13 +839,16 @@ getDirectoryContents path =
     bracket
       (Posix.openDirStream path)
       Posix.closeDirStream
-      loop
+      start
  where
-  loop dirp = do
-     e <- Posix.readDirStream dirp
-     if null e then return [] else do
-       es <- loop dirp
-       return (e:es)
+  start dirp =
+      loop id
+    where
+      loop acc = do
+        e <- Posix.readDirStream dirp
+        if null e
+          then return (acc [])
+          else loop (acc . (e:))
 #else
   bracket
      (Win32.findFirstFile (path </> "*"))



More information about the ghc-commits mailing list