summaryrefslogtreecommitdiff
path: root/utils/hpc/HpcUtils.hs
diff options
context:
space:
mode:
authorDavid Feuer <David.Feuer@gmail.com>2014-10-01 23:34:29 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2014-10-01 23:38:32 +0200
commit2a8856884de7d476e26b4ffa829ccb3a14d6f63e (patch)
treea5ba7fc47baf0cf68cf01336a38c963ad19c43b2 /utils/hpc/HpcUtils.hs
parent53a2d46d185bcffe005e84b4e7acf6b196f2329e (diff)
downloadhaskell-2a8856884de7d476e26b4ffa829ccb3a14d6f63e.tar.gz
Use dropWhileEndLE p instead of reverse . dropWhile p . reverse
Summary: Using `dropWhileEndLE` tends to be faster and easier to read than the `reverse . dropWhile p . reverse` idiom. This also cleans up some other, nearby, messes. Fix #9616 (incorrect number formatting potentially leading to incorrect numbers in output). Test Plan: Run validate Reviewers: thomie, rwbarton, nomeata, austin Reviewed By: nomeata, austin Subscribers: simonmar, ezyang, carter, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D259 GHC Trac Issues: #9623, #9616 Conflicts: compiler/basicTypes/OccName.lhs
Diffstat (limited to 'utils/hpc/HpcUtils.hs')
-rw-r--r--utils/hpc/HpcUtils.hs4
1 files changed, 4 insertions, 0 deletions
diff --git a/utils/hpc/HpcUtils.hs b/utils/hpc/HpcUtils.hs
index 5655f837f3..73d9cd3a87 100644
--- a/utils/hpc/HpcUtils.hs
+++ b/utils/hpc/HpcUtils.hs
@@ -3,6 +3,10 @@ module HpcUtils where
import Trace.Hpc.Util
import qualified Data.Map as Map
+dropWhileEndLE :: (a -> Bool) -> [a] -> [a]
+-- Spec: dropWhileEndLE p = reverse . dropWhileEnd . reverse
+dropWhileEndLE p = foldr (\x r -> if null r && p x then [] else x:r) []
+
-- turns \n into ' '
-- | grab's the text behind a HpcPos;
grabHpcPos :: Map.Map Int String -> HpcPos -> String