On Feb 17, 10:35 pm, Nils Bruin <nbr...@sfu.ca> wrote:

> Indeed, we have
>
> sage: MyHash.__dict__["__hash__"](h)
> 0
> sage: print MyHash.__hash__(h)
> 0
> sage: h.__hash__()
> 0
Incidentally, this suggests that hash(a) does the following:
 1] see if type(a).tp_hash is set. If so, use this
 2] see if type(a) is eligible to inherit hash. If so, do "__hash__"
lookup in the usual way.

That suggests that classes that implement hash themselves can hash
*much* faster than classes that inherit from it. I've scanned through
PyType_Ready code but wasn't able to find any place where the tp_hash
slot gets filled in from a superclass.

This may apply for other slots too: manually filling in slots with
routines that otherwise would be inherited could lead to significant
speedups. Of course, you're breaking Python semantics. If
subsequently, a super gets monkeypatched, your subclass won't pick up
on the change.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to