我想知道,内联小型私有函数是否是一个好主意?就我而言,这些函数仅出于可读性目的而存在,而且我知道,它们仅被调用过几次,因此较大的字节码大小无关紧要。
我知道,性能提升也可能是微不足道的,因为我没有传递函数类型(编译器实际上警告我),但是让我们假设它是我们应用程序中的热点。
实际示例:
我有一个理论上无限的符号带(像图灵机一样),它由两个阵列(分别是位置<0和位置> = 0的左侧和右侧)建模。现在,我已经进行了许多读写操作,这些操作被假定为很多东西。
在Java中,我有:
/**
* @param cell the cell
* @return the symbol at the specified cell
*/
public char read(int cell) {
char[] tape;
if (cell < 0) {
tape = left;
cell = -cell - 1;
} else {
tape = right;
}
return cell < tape.length ? tape[cell] : blank;
}
/**
* Writes a symbol to the specified cell.
* @param c the symbol
* @param cell the cell
*/ …Run Code Online (Sandbox Code Playgroud)