[commit: packages/filepath] master: Refactor splitDirectories (ba8bae5)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:34:14 UTC 2015


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

On branch  : master
Link       : http://git.haskell.org/packages/filepath.git/commitdiff/ba8bae53fe80189112b9f19e46fad2edf1530ab3

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

commit ba8bae53fe80189112b9f19e46fad2edf1530ab3
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Thu Oct 23 12:59:29 2014 +0200

    Refactor splitDirectories
    
    Use `dropTrailingPathSeparator` instead of the custom function `g` to remove
    trailing path separators from FilePath components generated with `splitPath`.
    
    Since `dropTrailingPathSeparator` does not change FilePath components
    for which isDrive is True, it is no longer necessary to handle the first
    FilePath component in a special way.


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

ba8bae53fe80189112b9f19e46fad2edf1530ab3
 System/FilePath/Internal.hs | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs
index f85e635..c684070 100644
--- a/System/FilePath/Internal.hs
+++ b/System/FilePath/Internal.hs
@@ -643,15 +643,7 @@ splitPath x = [drive | drive /= ""] ++ f path
 -- > Valid x => joinPath (splitDirectories x) `equalFilePath` x
 -- > splitDirectories "" == []
 splitDirectories :: FilePath -> [FilePath]
-splitDirectories path =
-        if hasDrive path then head pathComponents : f (tail pathComponents)
-        else f pathComponents
-    where
-        pathComponents = splitPath path
-
-        f = map g
-        g x = if null res then x else res
-            where res = takeWhile (not . isPathSeparator) x
+splitDirectories = map dropTrailingPathSeparator . splitPath
 
 
 -- | Join path elements back together.



More information about the ghc-commits mailing list