From d71d0a1dca102d0ef8b035a061d51c4e69d8fd19 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 6 Jul 2009 23:24:14 +0200 Subject: [PATCH] Take the foldl out of Loader.fixNodes Currently Loader.fixNodes is foldl' with a complicated function. It makes more sense to take foldl' out of this function (and put it into the caller) and let fixNodes be only this internal function. --- Ganeti/HTools/Loader.hs | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index 99f753946..85fb5bf55 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -95,29 +95,24 @@ assocEqual = (==) `on` fst -- | For each instance, add its index to its primary and secondary nodes. fixNodes :: [(Ndx, Node.Node)] - -> [(Idx, Instance.Instance)] + -> (Idx, Instance.Instance) -> [(Ndx, Node.Node)] -fixNodes = - foldl' (\accu (idx, inst) -> - let - pdx = Instance.pnode inst - sdx = Instance.snode inst - pold = fromJust $ lookup pdx accu - pnew = Node.setPri pold idx - pnew' = Node.addCpus pnew (Instance.vcpus inst) - ac1 = deleteBy assocEqual (pdx, pold) accu - ac2 = (pdx, pnew'):ac1 - in - if sdx /= Node.noSecondary then - let - sold = fromJust $ lookup sdx accu - snew = Node.setSec sold idx - ac3 = deleteBy assocEqual (sdx, sold) ac2 - ac4 = (sdx, snew):ac3 - in ac4 - else - ac2 - ) +fixNodes accu (idx, inst) = + let + pdx = Instance.pnode inst + sdx = Instance.snode inst + pold = fromJust $ lookup pdx accu + pnew = Node.setPri pold idx + pnew' = Node.addCpus pnew (Instance.vcpus inst) + ac1 = deleteBy assocEqual (pdx, pold) accu + ac2 = (pdx, pnew'):ac1 + in + if sdx /= Node.noSecondary + then let sold = fromJust $ lookup sdx accu + snew = Node.setSec sold idx + ac3 = deleteBy assocEqual (sdx, sold) ac2 + in (sdx, snew):ac3 + else ac2 -- | Compute the longest common suffix of a list of strings that -- | starts with a dot. @@ -141,7 +136,7 @@ mergeData :: (Node.AssocList, -> Result (Node.List, Instance.List, String) mergeData (nl, il) = do let - nl2 = fixNodes nl il + nl2 = foldl' fixNodes nl il il3 = Container.fromAssocList il nl3 = Container.fromAssocList (map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2) -- GitLab