small opt to absPath
Noticed that it gets the CWD unncessarily when the path is absolute. I have not benchmarked this, but I guess that the small overhead of isAbsolute is so tiny compared to the system call that it's worth it even if most of the time relative paths are passed to absPath.
This commit is contained in:
parent
14dfd297a4
commit
662e5a5db9
1 changed files with 13 additions and 4 deletions
|
@ -41,7 +41,7 @@ import Prelude
|
|||
|
||||
import Utility.Monad
|
||||
import Utility.UserInfo
|
||||
import Utility.Directory
|
||||
import Utility.SystemDirectory
|
||||
import Utility.Split
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
|
@ -73,6 +73,8 @@ simplifyPath path = dropTrailingPathSeparator $
|
|||
p' = dropTrailingPathSeparator p
|
||||
|
||||
{- Makes a path absolute.
|
||||
-
|
||||
- Also simplifies it using simplifyPath.
|
||||
-
|
||||
- The first parameter is a base directory (ie, the cwd) to use if the path
|
||||
- is not already absolute, and should itsef be absolute.
|
||||
|
@ -123,13 +125,20 @@ dirContains a b = a == b
|
|||
norm = normalise . simplifyPath
|
||||
|
||||
{- Converts a filename into an absolute path.
|
||||
-
|
||||
- Also simplifies it using simplifyPath.
|
||||
-
|
||||
- Unlike Directory.canonicalizePath, this does not require the path
|
||||
- already exists. -}
|
||||
absPath :: FilePath -> IO FilePath
|
||||
absPath file = do
|
||||
cwd <- getCurrentDirectory
|
||||
return $ absPathFrom cwd file
|
||||
absPath file
|
||||
-- Avoid unncessarily getting the current directory when the path
|
||||
-- is already absolute. absPathFrom uses simplifyPath
|
||||
-- so also used here for consistency.
|
||||
| isAbsolute file = return $ simplifyPath file
|
||||
| otherwise = do
|
||||
cwd <- getCurrentDirectory
|
||||
return $ absPathFrom cwd file
|
||||
|
||||
{- Constructs a relative path from the CWD to a file.
|
||||
-
|
||||
|
|
Loading…
Reference in a new issue