aboutsummaryrefslogtreecommitdiffstats
path: root/ShellPrompt.hs
diff options
context:
space:
mode:
authorgwern0 <gwern0@gmail.com>2007-10-16 01:48:50 +0200
committergwern0 <gwern0@gmail.com>2007-10-16 01:48:50 +0200
commit47943248fb5959182b9351bf5954f4c8fdbdd1ae (patch)
treea47e2f15c6c79c1344a2692f90c38834d65bc9e8 /ShellPrompt.hs
parent2527d001e977e346b8c70bbb61c3a828b8b82eec (diff)
downloadXMonadContrib-47943248fb5959182b9351bf5954f4c8fdbdd1ae.tar.gz
XMonadContrib-47943248fb5959182b9351bf5954f4c8fdbdd1ae.tar.xz
XMonadContrib-47943248fb5959182b9351bf5954f4c8fdbdd1ae.zip
ShellPrompt.hs: a quick optimization of nub
I saw some complaints about ShellPrompt being slow - and noticed it myself - and it seems ShellPrompt uses 'nub' in an awkward place to uniquefy input. Nub doesn't perform well on long lists, but I once ran into a similar problem and the suggested solution was something clever: convert to a Set and then back to a List. Sets can't have duplicate entries, and they uniquefy faster than nub. The price is that the output is not sorted the same as nub's output would be, but this is OK because the output of (toList . fromList) is immediately passed to 'sort' - which should then produce the same output for both versions. I haven't really tested this but on long directories this should help. darcs-hash:20071015234850-f7719-ce02426337ffbbfb15dd1999713075c5aada81bd.gz
Diffstat (limited to 'ShellPrompt.hs')
-rw-r--r--ShellPrompt.hs3
1 files changed, 2 insertions, 1 deletions
diff --git a/ShellPrompt.hs b/ShellPrompt.hs
index b52fda8..9ff06c3 100644
--- a/ShellPrompt.hs
+++ b/ShellPrompt.hs
@@ -26,6 +26,7 @@ import XMonadContrib.Dmenu
import Control.Monad
import Data.List
+import Data.Set (toList, fromList)
import System.Directory
import System.IO
import System.Environment
@@ -60,7 +61,7 @@ getShellCompl s
| s /= "" && last s /= ' ' = do
f <- fmap lines $ runProcessWithInput "/bin/bash" [] ("compgen -A file " ++ s ++ "\n")
c <- commandCompletionFunction s
- return . map escape . sort . nub $ f ++ c
+ return . map escape . sort . (toList . fromList) $ f ++ c
| otherwise = return []
commandCompletionFunction :: String -> IO [String]