avoid list traverse on queue
I wanted to use M.insertWith' (\_ l -> file:l) action [] m , but the order of the parameters and which to ignore is not clear, and seems unsafe to rely on.
This commit is contained in:
parent
4ea0b7c288
commit
135d75f2b9
1 changed files with 5 additions and 1 deletions
|
@ -57,7 +57,11 @@ add :: Queue -> String -> [CommandParam] -> FilePath -> Queue
|
||||||
add (Queue n m) subcommand params file = Queue (n + 1) m'
|
add (Queue n m) subcommand params file = Queue (n + 1) m'
|
||||||
where
|
where
|
||||||
action = Action subcommand params
|
action = Action subcommand params
|
||||||
m' = M.insertWith' (++) action [file] m
|
-- There are probably few items in the map, but there
|
||||||
|
-- can be a lot of files per item. So, optimise adding
|
||||||
|
-- files.
|
||||||
|
m' = M.insertWith' const action files m
|
||||||
|
files = file:(M.findWithDefault [] action m)
|
||||||
|
|
||||||
{- Number of items in a queue. -}
|
{- Number of items in a queue. -}
|
||||||
size :: Queue -> Int
|
size :: Queue -> Int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue