Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: David Morley <morley@AI.SRI.COM> - 2008-01-20 06:01:40
|
Jim, Thanks for the link to the CollectionsIntegration page. How do I find it from the wiki front page? I suspect that there are similar pages on other topics that might be of interest to me and I would like to know where to look. I am actually working with PySequence rather than PySequenceList. I've implemented a class something like a tuple with a functor symbol (like a Prolog term such as "functor(arg0,arg1,arg2)"), and was looking at PySequenceList/PyTuple for inspiration, but ended up basing my class on PySequence. Because I have *lots* of terms with just one or two elements, I'm special-casing those and using PyObject arrays only for longer sequences. From that perspective, PySequenceList looks a tad "chubby" ;-). I thought that it shouldn't take much to de-generify my class and rip out the functor to give a decent tuple substitute (although I suspect the special-casing of short sequences would have to be dropped to make it possible to subclass in Jython). - David On 20/01/2008, at 1:56 PM, Jim Baker wrote: > Is it possible we may just want to get rid of Jython's own array- > based implementation (as realized through a fair amount of work, as > David points out, in PySequenceList) in favor of using ArrayList > (and perhaps other concrete implementations of List)? This had been > investigated earlier ( http://wiki.python.org/jython/ > CollectionsIntegration), and the answer then was no, but I don't > know how much of this was based on efficiently supporting Java 1.4 > and earlier. > > Of course this is not an immediate priority: this code is working, > and we'd want to benchmark against any changes. But at least we > have good unit tests to validate any changes. > > However, it would suggest that if you're working with > PySequenceList outside of the Jython core, you might be depending > too much on Jython's internal implementation. > > - Jim > > On Jan 19, 2008 5:44 PM, David Morley <morley@...> wrote: > I am looking through the Jython PyTuple and PyList classes and I have > a few questions/suggestions: > > (1) I notice that each PySequenceList (such as a PyTuple or PyList) > has an instance of PyObjectList, which has a PyObjectArray, which has > a PyObject[]. Thus each new PySequenceList requires the allocation of > an array and three Java objects. This also means that calling > PySequenceList's pyget method calls PyObjectLists's pyget method, > which calls PyObjectArray's get method, which accesses the underlying > array. Shouldn't it be possible to fold all this into PySequenceList, > so that it has a PyObject[] directly? I presume there is some reason > why this isn't done, I just don't know what it is. > > (2) The fastSequence static method of PySequence trusts the PyList > and PyTuple __len__ methods to tell the truth about their lengths. > Would it be possible to introduce a new interface that both PyList > and PyTuple implement and have fastSequence test for this interface > rather than PyTuple or PyList? This would allow other, user-defined > subclasses of PySequence to share this behavior. > > (3) Where the fastSequence static method of PySequence is not able to > return the given sequence, it could test whether the sequence > implements the List interface and if so, use the toArray method to > construct a PyObject[] rather than constructing an empty list and > appending to it. > > If any of these suggestions sound reasonable, I would be happy to try > implementing them myself and submitting patches. > > - David |