I tried to do this google but no luck.
I have a very large switch, and some cases are obviously more common than others.
So, I would like to know if the order is really followed, and the "upper" cases are checked to the "lower", so they are evaluated faster.
I would like to keep my order, but if it hurts the speed, then reordering the branches would be a good idea.
To illustrate:
switch (mark) { case Ion.NULL: return null; case Ion.BOOLEAN: return readBoolean(); case Ion.BYTE: return readByte(); case Ion.CHAR: return readChar(); case Ion.SHORT: return readShort(); case Ion.INT: return readInt(); case Ion.LONG: return readLong(); case Ion.FLOAT: return readFloat(); case Ion.DOUBLE: return readDouble(); case Ion.STRING: return readString(); case Ion.BOOLEAN_ARRAY: return readBooleans(); case Ion.BYTE_ARRAY: return readBytes(); case Ion.CHAR_ARRAY: return readChars(); case Ion.SHORT_ARRAY: return readShorts(); case Ion.INT_ARRAY: return readInts(); case Ion.LONG_ARRAY: return readLongs(); case Ion.FLOAT_ARRAY: return readFloats(); case Ion.DOUBLE_ARRAY: return readDoubles(); case Ion.STRING_ARRAY: return readStrings(); default: throw new CorruptedDataException("Invalid mark: " + mark); }
java switch-statement
MightyPork Apr 21 '14 at 19:36 2014-04-21 19:36
source share