On Jan 12, 2010, at 5:04 AM, Sturla Molden wrote:

> I'd like to make a different suggestion. What about a keyword to pass
> after cdef in the declaration of the object to indicate the vtab can
> be skipped? I e an assertion that the object will be of the declared
> type. This will maintain better compatibility with Python.
>
> cdef Foo bar = Foo()
> cdef inline Foo fastbar = bar

Hmm... The notion of an "inline object" to me evokes allocating on the  
stack, or passing by value, or something like that--not ignoring type  
information when doing method dispatching. This isn't too important-- 
another keyword could be found.

> bar.method() # through vtab
> fastbar.method() # direct call

There is already a more explicit way to get this behavior:

cdef class A:
     cdef identify(self):
         print "I'm an A"

cdef class B(A):
     cdef identify(self):
         print "I'm a B"

cdef A a = A()
cdef B b = B()

a.identify() # prints "I'm an A"
b.identify() # prints "I'm a B"
A.identify(b) # prints "I'm an A"

It could probably be optimized to a direct call if desired by making  
the type vtab store const function pointers.

In any case, a non-overridable inline cdef method doesn't break Python  
semantics. (Well, you can't override it, but that's caught at compile  
time, rather than potentially surprising an end user at runtime.)

- Robert

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

Reply via email to