Re: Eliminating Special Method Lookup

Laura Creighton <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <[email protected]>
In a message of Mon, 07 Dec 2015 14:25:26 -0700, Jim Baker writes:
>Laura,
>
>Binary operations like + are compiled to Java bytecode to use
>PyObject::_add; this in turn dispatches through PyObject::_basic_add, which
>in turns goes through, for classes that derive from object,
>PyObjectDerived::#__add__ with a boilerplate implementation like so:
>
>    public PyObject __add__(PyObject other) {
>        PyType self_type=getType();
>        PyObject impl=self_type.lookup("__add__");
>        if (impl!=null) {
>            PyObject res=impl.__get__(this,self_type).__call__(other);
>            if (res==Py.NotImplemented)
>                return null;
>            return res;
>        }
>        return super.__add__(other);
>    }
>
>This means that the lookup is only against the type, not against the
>object's __dict__. So we follow the same data model for special methods
>that CPython uses.
>
>This process should inline well for the more common case of adding ints and
>floats, which was the conclusion of the analysis that Cliff Click performed
>a few years ago at the JVM Language Summit (as part of a study of Jython
>and other alternative JVM languages).
>
>- Jim

Good to hear.  Every so often python-dev goes off and makes some
momentous decision that has enormous impact on other python implementations
without first checking with the other implementations to see exactly
how much hardship this would cause.  Glad to see I was wrong in this
case. :)

Laura

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.