|
I ran into this problem as well. I can't reproduce it with Andrzej's test case, but here's one equally simple where I can:
public class Bug_57 It seems that Janino is using the right algorithm to choose between TABLESWITCH and LOOKUPSWITCH. Unfortunately, it's using an int to store the range, so when the difference between the smallest key and the largest key exceeds 2**31-1, it overflows and makes the wrong decision. Ironically, a very large range is the worst possible time to choose TABLESWITCH, hence the very large class files. The easiest fix is just to use a long to hold the range. Here's a patch against Janino 2.4.3: — janino-2.4.3/src/org/codehaus/janino/UnitCompiler.java 2006-05-11 23:05:12.000000000 -0500 // Generate TABLESWITCH or LOOKUPSWITCH instruction.
It seems that the CVS archive is not responding, so I couldn't be sure this is the latest version. Fixed it as propsed. Also added an optimization for SWITCH without CASE labels.
|
||||||||||||||||||||||||||||||||||||||||||||
compiles to a class file of 517 bytes.
What version of JANINO are you using? What is the precise content of your source file? How do you compile it (Compiler, ScriptEvaluator, ...) ?