From 6a9a9bd5a316f143964574e5ed12eb69b1d17c41 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 31 Oct 2010 01:51:50 -0400 Subject: another memory optimisation This time memory leaked if lots of UUIDs needed to be pretty-printed, as in a get or drop of many files. Essentially the same strict read buffering problem that affected the LocationLog underneath though. uuidMap really could stand to be cached, as the uuid log is read many times in this case. But it is a fairly edge case. --- Utility.hs | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'Utility.hs') diff --git a/Utility.hs b/Utility.hs index 233825b65..e7b4b510b 100644 --- a/Utility.hs +++ b/Utility.hs @@ -6,7 +6,6 @@ -} module Utility ( - withFileLocked, hGetContentsStrict, parentDir, relPathCwdToDir, @@ -28,21 +27,6 @@ import System.IO.HVFS import System.FilePath import System.Directory -{- Let's just say that Haskell makes reading/writing a file with - - file locking excessively difficult. -} -withFileLocked file mode action = do - -- TODO: find a way to use bracket here - handle <- openFile file mode - lockfd <- handleToFd handle -- closes handle - waitToSetLock lockfd (lockType mode, AbsoluteSeek, 0, 0) - handle' <- fdToHandle lockfd - ret <- action handle' - hClose handle' - return ret - where - lockType ReadMode = ReadLock - lockType _ = WriteLock - {- A version of hgetContents that is not lazy. Ensures file is - all read before it gets closed. -} hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s -- cgit v1.2.3