From d45ab327b0ca4fe949c13b95fc7eebb8c8d74a5d Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 5 Apr 2020 19:45:28 -0400 Subject: [PATCH] Only perform the comparisons once --- src/ShellCheck/Fixer.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ShellCheck/Fixer.hs b/src/ShellCheck/Fixer.hs index 16bdd98..1409b24 100644 --- a/src/ShellCheck/Fixer.hs +++ b/src/ShellCheck/Fixer.hs @@ -273,10 +273,10 @@ getPrefixSum = f 0 where f sum _ PSLeaf = sum f sum target (PSBranch pivot left right cumulative) = - case () of - _ | target < pivot -> f sum target left - _ | target > pivot -> f (sum+cumulative) target right - _ -> sum+cumulative + case target `compare` pivot of + LT -> f sum target left + GT -> f (sum+cumulative) target right + EQ -> sum+cumulative -- Add a value to the Prefix Sum tree at the given index. -- Values accumulate: addPSValue 42 2 . addPSValue 42 3 == addPSValue 42 5 @@ -285,10 +285,10 @@ addPSValue key value tree = if value == 0 then tree else f tree where f PSLeaf = PSBranch key PSLeaf PSLeaf value f (PSBranch pivot left right sum) = - case () of - _ | key < pivot -> PSBranch pivot (f left) right (sum + value) - _ | key > pivot -> PSBranch pivot left (f right) sum - _ -> PSBranch pivot left right (sum + value) + case key `compare` pivot of + LT -> PSBranch pivot (f left) right (sum + value) + GT -> PSBranch pivot left (f right) sum + EQ -> PSBranch pivot left right (sum + value) prop_pstreeSumsCorrectly kvs targets = let