easymock/objenesis

Unnecessary cast in UnsafeFactoryInstantiator

Closed this issue · 1 comments

newInstance code is

return type.cast(unsafe.allocateInstance(type));

while it could be just:

return (T) unsafe.allocateInstance(type);

I'm not sure, but the cast may affect performance.

No, there's no difference. I'd remove cast anyway.

Benchmark                                                                       Mode  Cnt   Score   Error  Units
unpackedCollections.arrayList.internal.InstantiatorBenchmark.reflection         avgt   12  12,215 ± 0,394  ns/op
unpackedCollections.arrayList.internal.InstantiatorBenchmark.unsafe             avgt   12  24,426 ± 0,832  ns/op
unpackedCollections.arrayList.internal.InstantiatorBenchmark.unsafeWithoutCast  avgt   12  24,858 ± 1,935  ns/op