For many years I have been asking myself how I could avoid the rule that was responsible for method resolution using the Villegas-Gayley pattern:
HoldPattern[class[params___].(f:Except[super])[args___] /; !TrueQ[$blockSub[class, f]] ] :> class[params].sub.f[args]
Although the method worked, it slowed down the evaluation of methods. I managed to find another mechanism that can rely solely on the traditional mathematica evaluation using UpValues.
The key idea consists in storing method definitions using the form o_MyClass.this.f[x_]
instead of o_MyClass.f[x_]
(the rewriting is done automatically, existing code still works). This then avoids having to intercept method calls of the form o.f[]
using the rule above that was previously required.
There was also a sub funtion responsible for executing a given definition (Class[object].sub.f[]
) that is not used anymore, that's why I'm bumping the version by 1 in the first part of the version.
My estimate is that the new method resolution is at least two times faster than before.