小编Jav*_*vaL的帖子

是否最好预先计算for循环的条件语句部分?

例如

int offset = getOffset();
int count = getCount();
int limit = count + offset;
for (int i; i < limit; i++) {}
Run Code Online (Sandbox Code Playgroud)

更优选

int offset = getOffset();
int count = getCount();
for (int i; i < offset + count; i++) {}
Run Code Online (Sandbox Code Playgroud)

如果Java VM在每次迭代时都进行了添加,那听起来就像是一个很大的开销.但如果编译器足够聪明以限制单次添加,我想保持我的代码简短.

java optimization coding-style

0
推荐指数
1
解决办法
66
查看次数

标签 统计

coding-style ×1

java ×1

optimization ×1