Commit bc383f20 authored by Andreas Klebinger's avatar Andreas Klebinger Committed by Ben Gamari

Simplify guard in createSwitchPlan.

Given that we have two unique keys (guaranteed by Map) checking that
`|range| == 1` is faster.

The fact that `x1 == lo` and `x2 == hi` is guaranteed by mkSwitchTargets
which removes values outside of the range.

Test Plan: ci

Reviewers: bgamari, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie, carter

Differential Revision:
parent 1bf70b20
......@@ -266,12 +266,11 @@ createSwitchPlan :: SwitchTargets -> SwitchPlan
createSwitchPlan (SwitchTargets _signed _range (Just defLabel) m)
| [(x, l)] <- M.toList m
= IfEqual x l (Unconditionally defLabel)
-- And another common case, matching booleans
-- And another common case, matching "booleans"
createSwitchPlan (SwitchTargets _signed (lo,hi) Nothing m)
| [(x1, l1), (x2,l2)] <- M.toAscList m
, x1 == lo
, x2 == hi
, x1 + 1 == x2
| [(x1, l1), (_x2,l2)] <- M.toAscList m
--Checking If |range| = 2 is enough if we have two unique literals
, hi - lo == 1
= IfEqual x1 l1 (Unconditionally l2)
createSwitchPlan (SwitchTargets signed range mbdef m) =
-- pprTrace "createSwitchPlan" (text (show ids) $$ text (show (range,m)) $$ text (show pieces) $$ text (show flatPlan) $$ text (show plan)) $
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment