Products » mBooster » Technical Support » mBooster documentation » Ch3-1-Optimizations » Ch3-1-8-Local Variable Optimizations
| Property settings This optimization is always turned ON. There is no control property file setting. |
mBooster automatically analyzes the uses and definitions of all local variables and will reuse variables where possible.
Original code
void someMethod() {
int locationX = ...
int locationY = ...
doSomeCalculation(locationX);
doSomeOtherCalculation(locationX, locationY);
// locationX is not used from here onwards, locationY is used further down
int damage = ...
if (damage > 10) {
...
}
}
mBooster recognizes that locationX and damage can be merged into a single local variable, and optimizes to the following equivalent code.
void someMethod() {
int mergedVariable = ...
int locationY = ...
doSomeCalculation(mergedVariable);
doSomeOtherCalculation(mergedVariable, locationY);
// locationX is not used from here onwards, locationY is used further down
mergedVariable = ...
if (mergedVariable > 10) {
...
}
}
mBooster performs many other optimizations on local variable usages. Another commonly performed manual optimization is to nest subexpressions deeply to eliminate the definition of local variables. mBooster also automates this optimization.
void someMethod() {
Pos myPos = getMyPos();
Pos monsterPos = getMonsterPos();
int dist = getDistance(myPos, monsterPos);
}
mBooster recognizes that the expressions can be nested, and will automatically transform the code to:
void someMethod() {
int dist = getDistance(getMyPos(), getMonsterPos());
}