From: David M. <morley@AI.SRI.COM> - 2008-01-20 00:46:25
|
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 |