9. JIT最適化の例: インライン化
double addAllSqrts(int max) {
double accum = 0;
for (int i = 0; i < max; i++) {
accum = addSqrt(accum, i);
}
return accum;
}
double addSqrt(double a, int b) {
return a + Math.sqrt(b);
}
public static void main(String[] args) {
for (int i = 0; i < 100000; ++i) {
(new Target()).addAllSqrts(10);
}
}
32. 動的型付け言語のメソッド呼び出し
def process_options(options)
for opt in options
process(opt.concat("?!"))
end
end
mock = Object.new
def mock.concat(arg)
"tested!"
end
options = ["yes", "no", mock]
process_options(options)
73. module Cache
4. インスタンス変数 def cache(value)
@cache = value
end
適用先: インスタンス変数アクセス end
● 呼び出し側selfの変数テーブルを参照 class Foo
include Cache
● 変数テーブルはクラスにより異なる end
class Bar
● モジュールが他のクラスに include Other
includeされている場合、クラスにより include Cache
end
"@cache"のテーブル内位置が異なる
● クラスの切り替え判定にguardWithTestを使う