From: <th...@us...> - 2009-07-15 02:31:49
|
Revision: 6537 http://jython.svn.sourceforge.net/jython/?rev=6537&view=rev Author: thobes Date: 2009-07-15 02:31:42 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Performance improvements for list multiplication. Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-07-13 16:32:44 UTC (rev 6536) +++ trunk/jython/src/org/python/core/PyList.java 2009-07-15 02:31:42 UTC (rev 6537) @@ -21,7 +21,7 @@ public class PyList extends PySequenceList implements List { public static final PyType TYPE = PyType.fromClass(PyList.class); - protected final List<PyObject> list; + private final List<PyObject> list; public volatile int gListAllocatedStatus = -1; public PyList() { @@ -77,6 +77,10 @@ return new PyList(list, false); } + List<PyObject> getList() { + return Collections.unmodifiableList(list); + } + private static List<PyObject> listify(Iterator<PyObject> iter) { List<PyObject> list = Generic.list(); while (iter.hasNext()) { @@ -215,11 +219,12 @@ throw Py.MemoryError(""); } - PyList newList = new PyList(); + PyObject[] elements = list.toArray(new PyObject[size]); + PyObject[] newList = new PyObject[newSize]; for (int i = 0; i < count; i++) { - newList.addAll(list); + System.arraycopy(elements, 0, newList, i * size, size); } - return newList; + return new PyList(newList); } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___ne___doc) Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-07-13 16:32:44 UTC (rev 6536) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-07-15 02:31:42 UTC (rev 6537) @@ -461,7 +461,7 @@ @Override public boolean containsAll(Collection c) { if (c instanceof PyList) { - return getList().containsAll(((PyList)c).list); + return getList().containsAll(((PyList)c).getList()); } else if (c instanceof PyTuple) { return getList().containsAll(((PyTuple)c).getList()); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |