Den 12. jan. 2010 kl. 15.44 skrev Stefan Behnel <[email protected]>:


>
>> cdef Foo bar = Foo()
>> cdef inline Foo fastbar = bar
>>
>> bar.method() # through vtab
>> fastbar.method() # direct call
>
> Why would you want to control this from user code?
>

Because I feel the common usecase for skipping the vtab indirection is  
calling a method repeatedly from user code.

This will not break Python semantics globally, but be a local  
optimization when the user knows the type of an object. Yes, we can  
already do this by declaring a const function pointer to the method;  
but this approach is less messy, and requires less knowledge of C.

Another way of defining this could be by inheritance. For example:

cdef class FastFoo(Foo, cython.finalobject):
     pass

cdef Foo bar = Foo()
cdef FastFoo fastbar = <FastFoo> bar


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

Reply via email to