mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Add IfElseSwap option
This enables an option that was being done unconditionally: to swap the `if` and `else` branches if the condition is shorter when negated. Enabled by default.
This commit is contained in:
parent
e62b5ffcb6
commit
08c429f22b
8 changed files with 44 additions and 17 deletions
7
unit_tests/regression.suite/if-else-noswap.lsl
Normal file
7
unit_tests/regression.suite/if-else-noswap.lsl
Normal file
|
@ -0,0 +1,7 @@
|
|||
default{timer(){
|
||||
|
||||
integer a = llGetLinkNumber();
|
||||
if (a == 3) llOwnerSay("1"); else llOwnerSay("2");
|
||||
if (!a) llOwnerSay("3"); else llOwnerSay("4");
|
||||
|
||||
}}
|
15
unit_tests/regression.suite/if-else-noswap.out
Normal file
15
unit_tests/regression.suite/if-else-noswap.out
Normal file
|
@ -0,0 +1,15 @@
|
|||
default
|
||||
{
|
||||
timer()
|
||||
{
|
||||
integer a = llGetLinkNumber();
|
||||
if (a == 3)
|
||||
llOwnerSay("1");
|
||||
else
|
||||
llOwnerSay("2");
|
||||
if (!a)
|
||||
llOwnerSay("3");
|
||||
else
|
||||
llOwnerSay("4");
|
||||
}
|
||||
}
|
1
unit_tests/regression.suite/if-else-noswap.run
Normal file
1
unit_tests/regression.suite/if-else-noswap.run
Normal file
|
@ -0,0 +1 @@
|
|||
main.py -O -ifelseswap -
|
|
@ -17,10 +17,10 @@ if ((key)((string)a)) ; else llDie();
|
|||
if (<a,0,0>) ; else llDie();
|
||||
if (<a,0,0,1>) ; else llDie();
|
||||
if ((list)a) ; else llDie();
|
||||
if (!a) llDie(); else llOwnerSay("ok");
|
||||
if (a == 3) llDie(); else llOwnerSay("ok");
|
||||
if (a > 5) if (a == 12) ; else llDie(); else llOwnerSay("ok");
|
||||
if (a == 12) llOwnerSay("1"); else if (a > 5) llOwnerSay("2");
|
||||
if (!a) llDie(); else llOwnerSay("1");
|
||||
if (a == 3) llDie(); else llOwnerSay("2");
|
||||
if (a > 5) if (a == 12) ; else llDie(); else llOwnerSay("3");
|
||||
if (a == 12) llOwnerSay("4"); else if (a > 5) llOwnerSay("5");
|
||||
if (a > 5) if (a == 12) ; else /*@f1*/; else llDie();
|
||||
if (a == 12) llDie(); else if (a > 5) /*@f4*/;
|
||||
// Fixed: Regression: this produces if (!(a == 3)) and no optimization kicks in
|
||||
|
|
|
@ -22,11 +22,11 @@ default
|
|||
if ((list)a == [])
|
||||
llDie();
|
||||
if (a)
|
||||
llOwnerSay("ok");
|
||||
llOwnerSay("1");
|
||||
else
|
||||
llDie();
|
||||
if (a ^ 3)
|
||||
llOwnerSay("ok");
|
||||
llOwnerSay("2");
|
||||
else
|
||||
llDie();
|
||||
if (5 < a)
|
||||
|
@ -35,14 +35,14 @@ default
|
|||
llDie();
|
||||
}
|
||||
else
|
||||
llOwnerSay("ok");
|
||||
llOwnerSay("3");
|
||||
if (a ^ 12)
|
||||
{
|
||||
if (5 < a)
|
||||
llOwnerSay("2");
|
||||
llOwnerSay("5");
|
||||
}
|
||||
else
|
||||
llOwnerSay("1");
|
||||
llOwnerSay("4");
|
||||
if (a < 6)
|
||||
llDie();
|
||||
if (a == 12)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue