Stefan Behnel wrote: > Hi, > > I think it would be nice to support 'cdef inline' methods in extension > types and let Cython call them without the normal method indirection, e.g. > > cdef class MyType: > cdef list large_list > cdef size_t y > > cdef big_method(self): > for x in self.large_list: > self.small_method(x) > > cdef inline small_method(self, x): > self.y += x > > would emit a direct call to the ..._small_method(self, x) C function in > big_method(), instead of passing through self->__pyx_vtab->small_method. > > This would require these methods to be non-overridable, which I think makes > sense for something declared 'inline'. > > Thoughts?
I remember wanting this feature when I first saw Cython (then never got around to it). So very much +1 on the feature, not sure about syntax. Java already has the concept of non-polymorphic dispatches through the "final" keyword. So what I was thinking was a new keyword would be used, so that one did "cdef inline final small_method". But -- there is probably not a use for inline non-final methods as they can't be inlined anyway, and I suppose the times one want a non-inline final method are very scarce (I suppose it would be for a method which took some time to execute but one wanted to actively prevent subclasses from overriding it -- which is not the rationale behind the feature at all). So I guess I'm +1 on the syntax proposed as well.. -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
