float denominator = 20 / 50 * 91 + 3;
float numeratorThing1 = 70 * 90;
float val1 = (56 * 90 + numeratorThing1) / denominator;
float val2 = (57 * 90 + numeratorThing1) / denominator;
float val3 = (58 * 90 + numeratorThing1) / denominator;Is just as optimal as code like this:
float val1 = (56 * 90 + 70 * 90) / (20 / 50 * 91 + 3);
float val2 = (57 * 90 + 70 * 90) / (20 / 50 * 91 + 3);
float val3 = (58 * 90 + 70 * 90) / (20 / 50 * 91 + 3);But does the compiler know to optimize out function calls that would return the same value each time?
for(vector<Widgets>::iterator iter = m_widgets.begin(); iter != m_widgets.end(); iter++) {
float val1 = (56 * 90 + iter->getWidth()) / getApplicationContext()->getScreenDimensions().getViewAspect();
float val2 = (57 * 90 + iter->getWidth()) / getApplicationContext()->getScreenDimensions().getViewAspect();
float val3 = (58 * 90 + iter->getWidth()) / getApplicationContext()->getScreenDimensions().getViewAspect();
}Into something that would be more optimal like this?
vector<Widgets>::iterator widgetsEnd = m_widgets.end();
for(vector<Widgets>::iterator iter = m_widgets.begin(); iter != widgetsEnd ; iter++) {
float width = iter->getWidth();
float viewAspect = getApplicationContext()->getScreenDimensions().getViewAspect();
float val1 = (56 * 90 + width) / viewAspect;
float val2 = (57 * 90 + width) / viewAspect;
float val3 = (58 * 90 + width) / viewAspect;
}