Products » mBooster » Technical Support » mBooster documentation » Ch3-1-Optimizations » Ch3-1-7-Redundancy Elimination
Redundancy Elimination removes expressions that have multiple occurrences in a method. By removing duplicate expressions Redundancy Elimination will increase the performance and may reduce the size of the application. It is important to point out that field reading and array loading are computationally expensive, and these could be automatically removed by mBooster.
Redundancy Elimination is able to remove redundant
void someMethod() {
int x = ...
int y = ...
int z = (x+y);
doSomeCalculation(x+y);
Player player = ...;
NonPlayerCharacter assassin = ...;
Weapon knife = ...;
if (assassin.power > 0) {
player.doDamage(assassin.power * knife.power);
}
int[] intArray = ...
for (int i = 0; i < intArray.length; i++) {
intArray[i] = ....
doSomething(intArray[i]);
doSomethingElse(intArray[i]);
}
}
When Redundancy Elimination is turned on and it is determined that the replacement is cost effective, mBooster optimizes the above code fragment to the following equivalent code, with the following replacements:
void someMethod() {
int x = ...
int y = ...
int z = (x+y);
doSomeCalculation(z);
Player player = ...;
NonPlayerCharacter assassin = ...;
Weapon knife = ...;
int assassinPower = assassin.power;
if (assassinPower > 0) {
player.doDamage(assassinPower * knife.power);
}
int[] intArray = ...
for (int i = 0; i < intArray.length; i++) {
int elementValue = ...
intArray[i] = elementValue;
doSomething(elementValue);
doSomethingElse(elementValue);
}
}
Be Careful
|
Tips
|