From: <fwi...@us...> - 2009-04-10 03:05:16
|
Revision: 6196 http://jython.svn.sourceforge.net/jython/?rev=6196&view=rev Author: fwierzbicki Date: 2009-04-10 03:05:14 +0000 (Fri, 10 Apr 2009) Log Message: ----------- properly handle setslice. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 02:22:11 UTC (rev 6195) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:05:14 UTC (rev 6196) @@ -155,14 +155,27 @@ } protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { - int size = list.size(); - for (int j = start; iter.hasNext(); j += step) { - PyObject item = iter.next(); - if (j >= size) { - list.add(item); - } else { - list.set(j, item); + if(step == 1) { + List<PyObject> copy = new ArrayList<PyObject>(); + copy.addAll(this.list.subList(0, start)); + if (iter != null) { + while (iter.hasNext()) { + copy.add(iter.next()); + } } + copy.addAll(this.list.subList(stop, this.list.size())); + this.list.clear(); + this.list.addAll(copy); + } else { + int size = list.size(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-10 03:49:09
|
Revision: 6199 http://jython.svn.sourceforge.net/jython/?rev=6199&view=rev Author: zyasoft Date: 2009-04-10 03:49:01 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Added back logic for PyList.equals(List) Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:32:30 UTC (rev 6198) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:49:01 UTC (rev 6199) @@ -775,6 +775,8 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); + } else if(o instanceof List) { // XXX copied from PyList, but... + return o.equals(this); // XXX shouldn't this compare using py2java? } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-10 03:53:10
|
Revision: 6200 http://jython.svn.sourceforge.net/jython/?rev=6200&view=rev Author: fwierzbicki Date: 2009-04-10 03:53:07 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Fix ClassCastException when not PySequence and not List. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:49:01 UTC (rev 6199) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:53:07 UTC (rev 6200) @@ -129,11 +129,13 @@ if (stop < start) { stop = start; } - if ((value instanceof PySequence) || (!(value instanceof List))) { + if (value instanceof PySequence) { if (value == this) { // copy value = new PyList((PySequence) value); } setsliceIterator(start, stop, step, value.asIterable().iterator()); + } else if (!(value instanceof List)) { + setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { System.err.println("List"); List valueList = (List) value.__tojava__(List.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-10 03:57:56
|
Revision: 6201 http://jython.svn.sourceforge.net/jython/?rev=6201&view=rev Author: fwierzbicki Date: 2009-04-10 03:57:54 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Pesimistic copy of list if not a PySequence and not a java.util.List. Needed to pass test_userlist, but feels like we could avoid sometimes, but how to check? Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:53:07 UTC (rev 6200) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:57:54 UTC (rev 6201) @@ -135,6 +135,8 @@ } setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (!(value instanceof List)) { + //XXX: can we avoid copying here? Needed to pass test_userlist + value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { System.err.println("List"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-10 04:01:56
|
Revision: 6202 http://jython.svn.sourceforge.net/jython/?rev=6202&view=rev Author: fwierzbicki Date: 2009-04-10 04:01:54 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Added null check. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 03:57:54 UTC (rev 6201) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 04:01:54 UTC (rev 6202) @@ -134,7 +134,7 @@ value = new PyList((PySequence) value); } setsliceIterator(start, stop, step, value.asIterable().iterator()); - } else if (!(value instanceof List)) { + } else if (value != null && !(value instanceof List)) { //XXX: can we avoid copying here? Needed to pass test_userlist value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-15 06:18:59
|
Revision: 6228 http://jython.svn.sourceforge.net/jython/?rev=6228&view=rev Author: zyasoft Date: 2009-04-15 06:18:52 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Slicing is faster. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-15 05:58:59 UTC (rev 6227) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-15 06:18:52 UTC (rev 6228) @@ -130,10 +130,12 @@ if (stop < start) { stop = start; } - if (value instanceof PySequence) { + if (value instanceof PyList) { if (value == this) { // copy value = new PyList((PySequence) value); } + setslicePyList(start, stop, step, (PyList)value); + } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { //XXX: can we avoid copying here? Needed to pass test_userlist @@ -161,16 +163,14 @@ protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { if(step == 1) { - List<PyObject> copy = new ArrayList<PyObject>(); - copy.addAll(this.list.subList(0, start)); + List<PyObject> insertion = new ArrayList<PyObject>(); if (iter != null) { while (iter.hasNext()) { - copy.add(iter.next()); + insertion.add(iter.next()); } } - copy.addAll(this.list.subList(stop, this.list.size())); - this.list.clear(); - this.list.addAll(copy); + list.subList(start, stop).clear(); + list.addAll(start, insertion); } else { int size = list.size(); for (int j = start; iter.hasNext(); j += step) { @@ -184,6 +184,24 @@ } } + protected void setslicePyList(int start, int stop, int step, PyList other) { + if(step == 1) { + list.subList(start, stop).clear(); + list.addAll(start, other.list); + } else { + int size = list.size(); + Iterator<PyObject> iter = other.listIterator(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); + } + } + } + } + @Override protected PyObject repeat(int count) { if (count < 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |