OPT.SMUL
Use the shift operator on 'a * b' expressions
Description
This rule flags any `a*b' expression.
"*" is an expensive operation; using the shift operator is faster and more efficient.
Example
package OPT;
public class SMUL {
public void calculate(int a) {
int mul = a * 4; // should be replaced with "a << 2".
int mul2 = 8 * a; // should be replaced with "a << 3".
int temp = a * 3;
}
}
Repair
package OPT;
public class SMUL {
public void calculate(int a) {
int mul = a << 2;
int mul2 = a << 3;
int temp = a * 3; // not possible to replace this with
shift operator.
}
}
|