PMD suggested in my GWT project that I should change my switch
to multiple if
s if it has fewer than 3 branches. I know that this is compiled to Javascript, but I wondered if it made any difference in GWT. Do you think the generated Javascript is more efficient with if's compared to switch
? Does the current GWT compiler (2.4) do any optimisation on this?
According to this site: http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html#the_switch_statement found via this answer: https://stackoverflow.com/a/2923007/66416 It does matter:
In JavaScript, if statements are generally faster than switch statements when there are just one or two conditions to be evaluated.
A quick scan of a compiled GWT 2.4 file found no replacements of 'small' switch statements into if statements. So it actually might be a useful suggestion of PMD.