On Jan 6, 2010, at 11:18 AM, Dag Sverre Seljebotn wrote:

> 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.

This has been floating around in the back of my head as well, so +1.

> 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..

One of the primary reasons for the Java final keyword is compiler  
optimization (either inlining and faster dispatching). Given that we  
already support the inline keyword, I think it makes sense to have it  
imply non-overridable.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to