You are here : Home » knowledge exchange
Using + as a string concatenation operator will result in a method call if the operands are not compile-time constants. Unrolling a loop to eliminate string concatenation can therefore save space.Again, this might not be worth the effort. For example, the following loop is compiled into 48 bytes of bytecode:for (int i = 0; i < 3; i++){imgs[i] = getImage (getCodeBase(), "G" + i + ".gif");}By unrolling the loop we eliminate the runtime concatenations and reduce the size of the bytecode to 39 bytes:imgs[0] = getImage (getCodeBase(), "G0.gif");imgs[1] = getImage (getCodeBase(), "G1.gif");imgs[2] = getImage (getCodeBase(), "G2.gif");Note that the three instances of getCodeBase() are a good candidate for common subexpression elimination


Copyright © 2005-2012 Narola Infotech, Custom Software & Website Development Company | All Rights Reserved.