On second thought, this object creation probably gets optimized away by
JIT when using escape analysis (since Java 6 update 14). But it would
still be useful in the Client VM.
Erkki Lindpere wrote:
> While working on my vector math optimizer plugin, I had an idea for
> optimizing Pimp-my-library, which would remove the object creation.
>
> For any pimping class, a companion object would be created:
>
> @Pimp class Baz(foo: Foo) {
> def bar(arg: Int) = ...
> }
>
> would create a companion object
>
> object Baz {
> def bar(foo: Foo, arg: Option[Int]) = ...
> }
>
> and any use of an implicit function:
> implicit def = whatever(foo: Foo) = new Baz(foo)
> whatever(foo).bar(None)
>
> would be transformed to
> Baz.bar(foo, None)
>
> Does this sound reasonable? Could be easily done using a compiler
> plug-in, I think. This misses some other cases of implicit
> conversions, but I think it would be useful anyway.
>
> Erkki
>