use RawFilePath getFileStatus for speed
Only done on those calls to getFileStatus that had a RawFilePath, not a FilePath. The others would probably be just as fast if converted to use it with toRawFilePath, but I'm not 100% sure. Note that genInodeCache' uses fromRawFilePath, but that value only gets used on Windows, so on unix the thunk will never be evaluated.
This commit is contained in:
parent
0e9d699ef3
commit
5f391179f1
9 changed files with 36 additions and 21 deletions
|
@ -33,7 +33,10 @@ getFileSize f = fmap (fromIntegral . fileSize) (getFileStatus f)
|
|||
getFileSize f = bracket (openFile f ReadMode) hClose hFileSize
|
||||
#endif
|
||||
|
||||
{- Gets the size of the file, when its FileStatus is already known. -}
|
||||
{- Gets the size of the file, when its FileStatus is already known.
|
||||
-
|
||||
- On windows, uses getFileSize. Otherwise, the FileStatus contains the
|
||||
- size, so this does not do any work. -}
|
||||
getFileSize' :: FilePath -> FileStatus -> IO FileSize
|
||||
#ifndef mingw32_HOST_OS
|
||||
getFileSize' _ s = return $ fromIntegral $ fileSize s
|
||||
|
|
|
@ -22,6 +22,7 @@ module Utility.InodeCache (
|
|||
readInodeCache,
|
||||
showInodeCache,
|
||||
genInodeCache,
|
||||
genInodeCache',
|
||||
toInodeCache,
|
||||
likeInodeCacheWeak,
|
||||
|
||||
|
@ -43,6 +44,7 @@ module Utility.InodeCache (
|
|||
import Common
|
||||
import Utility.TimeStamp
|
||||
import Utility.QuickCheck
|
||||
import qualified Utility.RawFilePath as R
|
||||
|
||||
import System.PosixCompat.Types
|
||||
import Data.Time.Clock.POSIX
|
||||
|
@ -184,6 +186,10 @@ genInodeCache :: FilePath -> TSDelta -> IO (Maybe InodeCache)
|
|||
genInodeCache f delta = catchDefaultIO Nothing $
|
||||
toInodeCache delta f =<< getFileStatus f
|
||||
|
||||
genInodeCache' :: RawFilePath -> TSDelta -> IO (Maybe InodeCache)
|
||||
genInodeCache' f delta = catchDefaultIO Nothing $
|
||||
toInodeCache delta (fromRawFilePath f) =<< R.getFileStatus f
|
||||
|
||||
toInodeCache :: TSDelta -> FilePath -> FileStatus -> IO (Maybe InodeCache)
|
||||
toInodeCache (TSDelta getdelta) f s
|
||||
| isRegularFile s = do
|
||||
|
|
|
@ -17,11 +17,12 @@
|
|||
module Utility.RawFilePath (
|
||||
RawFilePath,
|
||||
readSymbolicLink,
|
||||
getFileStatus,
|
||||
) where
|
||||
|
||||
#ifndef mingw32_HOST_OS
|
||||
import Utility.FileSystemEncoding (RawFilePath)
|
||||
import System.Posix.Files.ByteString
|
||||
import System.Posix.ByteString.FilePath
|
||||
#else
|
||||
import qualified Data.ByteString as B
|
||||
import qualified System.PosixCompat as P
|
||||
|
@ -29,4 +30,7 @@ import Utility.FileSystemEncoding
|
|||
|
||||
readSymbolicLink :: RawFilePath -> IO RawFilePath
|
||||
readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f)
|
||||
|
||||
getFileStatus :: RawFilePath -> IO FileStatus
|
||||
getFileStatus = P.getFileStatus . fromRawFilePath
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue