gpt4 book ai didi

java - 开关盒顺序会影响速度吗?

转载 作者:IT老高 更新时间:2023-10-28 11:43:55 27 4
gpt4 key购买 nike

我试过用谷歌搜索,但没有运气。

我有一个很大的转变,有些情况显然比其他情况更常见

所以我想知道订单是否真的保持原样,并且“上”案例在“下”之前得到测试,因此评估速度更快。

我想保持我的订单,但如果它影响速度,那么重新排序分支将是一个好主意。

为了说明:

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);
}

最佳答案

重新排序 switch 语句没有任何效果。

查看 Java 字节码规范,switch 可以编译为 lookupswitchtableswitch 指令,打开 >intlookupswitch 总是以排序顺序使用可能的值进行编译,因此重新排序代码中的常量无关紧要,并且 tableswitch 只是有一个可能的相对跳转数组到指定的偏移量,因此它也从不关心原始顺序。

http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.lookupswitchhttp://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.tableswitch了解详情。

关于java - 开关盒顺序会影响速度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23204580/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com