开关机箱顺序会影响速度吗?
2022-08-31 12:16:34
我试图谷歌这个,但没有运气。
我有一个非常大的开关,有些情况显然比其他情况更常见。
因此,我想知道订单是否真的保持原样,并且“较高”情况在“较低”情况之前进行测试,因此可以更快地进行评估。
我想保留我的订单,但如果它损害了速度,那么重新排序分支将是一个好主意。
举例说明:
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);
}