From 9e2fb8c3dd3cb6cda9be0a0ca6ebbbdd61b8580d Mon Sep 17 00:00:00 2001
From: Hans-Peter Deifel <hpd@hpdeifel.de>
Date: Wed, 1 Aug 2018 11:53:06 +0200
Subject: [PATCH] Remove an unnecessary mapM

We allocated a complete vector of H3s in splitBlock, just to calculate
the pmc.
---
 src/MA/Algorithm/Split.hs | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/MA/Algorithm/Split.hs b/src/MA/Algorithm/Split.hs
index 9ee1b5e..5b3a303 100644
--- a/src/MA/Algorithm/Split.hs
+++ b/src/MA/Algorithm/Split.hs
@@ -71,9 +71,14 @@ splitBlock b = ask >>= \(as, queue) -> lift $ do
   -- b has marked states, so b1 is guaranteed to be non-empty
   (Just b1, bunmarked) <- Partition.splitMarked (partition as) b
 
-  pmc <- Partition.statesOfBlock (partition as) b1
-    >>= mapM (VM.read (h3Cache as))
-    >>= return . possibleMajorityCandidate
+  -- NOTE: We need to use unsafePerformIO here, because all vector sortBy
+  -- functions expect a pure predicate. Since our predicate is only monadic
+  -- because we need to _read_ from a mutable vector and doesn't have side
+  -- effects, this should be safe.
+  let unsafeH3 = unsafeDupablePerformIO . unsafeSTToIO . VM.read (h3Cache as)
+
+  !pmc <- (possibleMajorityCandidate . V.map unsafeH3) <$>
+          Partition.statesOfBlock (partition as) b1
 
   -- the pmc occurs in b1, so b1' has to be non-empty
   (Just b1', b2) <- Partition.splitByM (partition as) b1
@@ -81,12 +86,7 @@ splitBlock b = ask >>= \(as, queue) -> lift $ do
 
   blocks <- ((b1':maybeToList bunmarked) ++) <$> case b2 of
     Nothing -> return []
-    -- NOTE: We need to use unsafePerformIO here, because all vector sortBy
-    -- functions expect a pure predicate. Since our predicate is only monadic
-    -- because we need to _read_ from a mutable vector and doesn't have side
-    -- effects, this should be safe.
-    Just b2' -> Partition.groupBy (partition as) b2'
-                  (unsafeDupablePerformIO . unsafeSTToIO . VM.read (h3Cache as))
+    Just b2' -> Partition.groupBy (partition as) b2' unsafeH3
 
   let enqueue = Queue.enqueue queue
 
-- 
GitLab