git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: fix broken cond-to-switch optimization
commit7cec700d0e7afb7f811a2696f9e5ec622bbcbabd authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 22 Jan 2017, 14:27 (10 years ago) parentddf7e59
1 file changed+7−7
src/Language/PureScript/CodeGen/Cpp/Optimizer/Blocks.hs+7−7
src/Language/PureScript/CodeGen/Cpp/Optimizer/Blocks.hs+7−7
@@ -21,7 +21,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
2121 ) where
2222
2323import Prelude.Compat
24−import Data.Either
24+import Data.Maybe
2525
2626import Language.PureScript.CodeGen.Cpp.AST
2727import Language.PureScript.CodeGen.Cpp.Types
@@ -94,16 +94,16 @@ collapseCtorChecksToSwitch = everywhereOnCpp collapse
9494 collapse (CppBlock cpps@(_:_:_)) = CppBlock (go cpps)
9595 where
9696 go cpps'@(cpp:_)
97− | Right (lhs, _, _) <- fromif Nothing cpp
98− , (otherCpps, ifs@(_:_:_)) <- partitionEithers $ fromif (Just lhs) <$> cpps'
99− = CppSwitch lhs ((\(_,b,c) -> (b,c)) <$> ifs) Nothing : otherCpps
97+ | Just (lhs, _, _) <- fromif Nothing cpp
98+ , ifs@(_:_:_) <- catMaybes . takeWhile (isJust) $ fromif (Just lhs) <$> cpps'
99+ = CppSwitch lhs ((\(_,b,c) -> (b,c)) <$> ifs) Nothing : drop (length ifs) cpps'
100100 go (cpp':cpps') = cpp' : go cpps'
101101 go cpp' = cpp'
102− fromif :: Maybe Cpp -> Cpp -> Either Cpp (Cpp, Cpp, Cpp)
102+ fromif :: Maybe Cpp -> Cpp -> Maybe (Cpp, Cpp, Cpp)
103103 fromif cond (CppIfElse (CppBinary EqualTo lhs rhs) stmt Nothing)
104104 | CppApp (CppVar f) _ <- lhs
105105 , f == getCtor
106106 , maybe True (lhs==) cond
107− = Right (lhs, rhs, stmt)
108− fromif _ cpp = Left cpp
107+ = Just (lhs, rhs, stmt)
108+ fromif _ _ = Nothing
109109 collapse cpp = cpp