From: <fwi...@us...> - 2008-12-23 19:35:45
|
Revision: 5794 http://jython.svn.sourceforge.net/jython/?rev=5794&view=rev Author: fwierzbicki Date: 2008-12-23 19:35:40 +0000 (Tue, 23 Dec 2008) Log Message: ----------- __doc__ for dict. Modified Paths: -------------- trunk/jython/src/org/python/core/PyDictionary.java Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2008-12-23 18:53:36 UTC (rev 5793) +++ trunk/jython/src/org/python/core/PyDictionary.java 2008-12-23 19:35:40 UTC (rev 5794) @@ -80,7 +80,7 @@ } } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___init___doc) @ExposedNew protected final void dict___init__(PyObject[] args, String[] keywords) { updateCommon(args, keywords, "dict"); @@ -107,7 +107,7 @@ return dict___len__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___len___doc) final int dict___len__() { return table.size(); } @@ -116,6 +116,7 @@ return dict___nonzero__(); } + //XXX: CPython's dict does not define __nonzero__ @ExposedMethod final boolean dict___nonzero__() { return table.size() != 0; @@ -129,7 +130,7 @@ return table.get(key); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___getitem___doc) protected final PyObject dict___getitem__(PyObject key) { PyObject result = table.get(key); if (result != null) { @@ -151,7 +152,7 @@ dict___setitem__(key,value); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___setitem___doc) final void dict___setitem__(PyObject key, PyObject value) { table.put(key, value); } @@ -160,7 +161,7 @@ dict___delitem__(key); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___delitem___doc) final void dict___delitem__(PyObject key) { Object ret = table.remove(key); if (ret == null) @@ -171,7 +172,7 @@ return dict___iter__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___iter___doc) final PyObject dict___iter__() { return iterkeys(); } @@ -180,7 +181,7 @@ return dict_toString(); } - @ExposedMethod(names = {"__repr__", "__str__"}) + @ExposedMethod(names = {"__repr__", "__str__"}, doc = BuiltinDocs.dict___str___doc) final String dict_toString() { ThreadState ts = Py.getThreadState(); if (!ts.enterRepr(this)) { @@ -208,7 +209,7 @@ return dict___eq__(ob_other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) final PyObject dict___eq__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); @@ -239,14 +240,14 @@ return dict___ne__(ob_other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___ne___doc) final PyObject dict___ne__(PyObject ob_other) { PyObject eq_result = __eq__(ob_other); if (eq_result == null) return null; return eq_result.__not__(); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___lt___doc) final PyObject dict___lt__(PyObject ob_other){ int result = __cmp__(ob_other); if(result == -2){ @@ -255,7 +256,7 @@ return result < 0 ? Py.True : Py.False; } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___gt___doc) final PyObject dict___gt__(PyObject ob_other){ int result = __cmp__(ob_other); if(result == -2){ @@ -264,7 +265,7 @@ return result > 0 ? Py.True : Py.False; } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___le___doc) final PyObject dict___le__(PyObject ob_other){ int result = __cmp__(ob_other); if(result == -2){ @@ -273,7 +274,7 @@ return result <= 0 ? Py.True : Py.False; } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___ge___doc) final PyObject dict___ge__(PyObject ob_other){ int result = __cmp__(ob_other); if(result == -2){ @@ -286,7 +287,7 @@ return dict___cmp__(ob_other); } - @ExposedMethod(type = MethodType.CMP) + @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.dict___cmp___doc) final int dict___cmp__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); @@ -337,7 +338,7 @@ return dict_has_key(key); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_has_key_doc) final boolean dict_has_key(PyObject key) { return table.containsKey(key); } @@ -346,7 +347,7 @@ return dict___contains__(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___contains___doc) final boolean dict___contains__(PyObject o) { return dict_has_key(o); } @@ -363,7 +364,7 @@ return dict_get(key,default_object); } - @ExposedMethod(defaults = "Py.None") + @ExposedMethod(defaults = "Py.None", doc = BuiltinDocs.dict_get_doc) final PyObject dict_get(PyObject key, PyObject default_object) { PyObject o = table.get(key); if (o == null) @@ -389,7 +390,7 @@ return dict_copy(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_copy_doc) final PyDictionary dict_copy() { return new PyDictionary(table); // no need to clone() } @@ -401,7 +402,7 @@ dict_clear(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_clear_doc) final void dict_clear() { table.clear(); } @@ -414,7 +415,7 @@ dict_update(new PyObject[] {other}, Py.NoKeywords); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_update_doc) final void dict_update(PyObject[] args, String[] keywords) { updateCommon(args, keywords, "update"); } @@ -516,6 +517,7 @@ return dict_setdefault(key,failobj); } + //XXX: needs __doc__ but CPython does not define setdefault @ExposedMethod(defaults = "Py.None") final PyObject dict_setdefault(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); @@ -526,6 +528,7 @@ } } + //XXX: needs __doc__ but CPython does not define setifabsent @ExposedMethod(defaults = "Py.None") final PyObject dict_setifabsent(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); @@ -553,7 +556,7 @@ return dict_pop(key, defaultValue); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.dict_pop_doc) final PyObject dict_pop(PyObject key, PyObject defaultValue) { if (!table.containsKey(key)) { if (defaultValue == null) { @@ -573,7 +576,7 @@ return dict_popitem(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { Iterator it = table.entrySet().iterator(); if (!it.hasNext()) @@ -593,7 +596,7 @@ return dict_items(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_items_doc) final PyList dict_items() { List<PyObject> list = new ArrayList<PyObject>(table.size()); for (Entry<PyObject, PyObject> entry : table.entrySet()) { @@ -609,12 +612,12 @@ return dict_keys(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_keys_doc) final PyList dict_keys() { return new PyList(new ArrayList<PyObject>(table.keySet())); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_values_doc) final PyList dict_values() { return new PyList(new ArrayList<PyObject>(table.values())); } @@ -626,7 +629,7 @@ return dict_iteritems(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_iteritems_doc) final PyObject dict_iteritems() { return new ItemsIter(table.entrySet()); } @@ -638,7 +641,7 @@ return dict_iterkeys(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_iterkeys_doc) final PyObject dict_iterkeys() { return new ValuesIter(table.keySet()); } @@ -650,7 +653,7 @@ return dict_itervalues(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict_itervalues_doc) final PyObject dict_itervalues() { return new ValuesIter(table.values()); } @@ -659,7 +662,7 @@ return dict___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.dict___hash___doc) final int dict___hash__() { throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-28 23:42:04
|
Revision: 6926 http://jython.svn.sourceforge.net/jython/?rev=6926&view=rev Author: pjenvey Date: 2009-10-28 23:41:45 +0000 (Wed, 28 Oct 2009) Log Message: ----------- coding standards Modified Paths: -------------- trunk/jython/src/org/python/core/PyDictionary.java Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2009-10-28 16:01:21 UTC (rev 6925) +++ trunk/jython/src/org/python/core/PyDictionary.java 2009-10-28 23:41:45 UTC (rev 6926) @@ -1,4 +1,7 @@ -// Copyright (c) Corporation for National Research Initiatives +/* + * Copyright (c) Corporation for National Research Initiatives + * Copyright (c) Jython Developers + */ package org.python.core; import java.util.AbstractSet; @@ -73,8 +76,8 @@ */ public PyDictionary(PyObject elements[]) { this(); - for (int i = 0; i < elements.length; i+=2) { - table.put(elements[i], elements[i+1]); + for (int i = 0; i < elements.length; i += 2) { + table.put(elements[i], elements[i + 1]); } } @@ -101,6 +104,7 @@ return d; } + @Override public int __len__() { return dict___len__(); } @@ -110,6 +114,7 @@ return table.size(); } + @Override public boolean __nonzero__() { return dict___nonzero__(); } @@ -120,10 +125,12 @@ return table.size() != 0; } + @Override public PyObject __finditem__(int index) { throw Py.TypeError("loop over non-sequence"); } + @Override public PyObject __finditem__(PyObject key) { return table.get(key); } @@ -146,8 +153,9 @@ throw Py.KeyError(key); } + @Override public void __setitem__(PyObject key, PyObject value) { - dict___setitem__(key,value); + dict___setitem__(key, value); } @ExposedMethod(doc = BuiltinDocs.dict___setitem___doc) @@ -155,6 +163,7 @@ table.put(key, value); } + @Override public void __delitem__(PyObject key) { dict___delitem__(key); } @@ -162,10 +171,12 @@ @ExposedMethod(doc = BuiltinDocs.dict___delitem___doc) final void dict___delitem__(PyObject key) { Object ret = table.remove(key); - if (ret == null) + if (ret == null) { throw Py.KeyError(key.toString()); + } } + @Override public PyObject __iter__() { return dict___iter__(); } @@ -175,6 +186,7 @@ return iterkeys(); } + @Override public String toString() { return dict_toString(); } @@ -187,14 +199,13 @@ } StringBuilder buf = new StringBuilder("{"); - for (Entry<PyObject, PyObject> entry : table.entrySet()) { buf.append((entry.getKey()).__repr__().toString()); buf.append(": "); buf.append((entry.getValue()).__repr__().toString()); buf.append(", "); } - if(buf.length() > 1){ + if (buf.length() > 1) { buf.delete(buf.length() - 2, buf.length()); } buf.append("}"); @@ -203,101 +214,113 @@ return buf.toString(); } - public PyObject __eq__(PyObject ob_other) { - return dict___eq__(ob_other); + @Override + public PyObject __eq__(PyObject otherObj) { + return dict___eq__(otherObj); } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) - final PyObject dict___eq__(PyObject ob_other) { + final PyObject dict___eq__(PyObject otherObj) { PyType thisType = getType(); - PyType otherType = ob_other.getType(); + PyType otherType = otherObj.getType(); if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return null; } - PyDictionary other = (PyDictionary)ob_other; + PyDictionary other = (PyDictionary)otherObj; int an = table.size(); int bn = other.table.size(); - if (an != bn) + if (an != bn) { return Py.False; + } PyList akeys = keys(); - for (int i=0; i<an; i++) { + for (int i = 0; i < an; i++) { PyObject akey = akeys.pyget(i); PyObject bvalue = other.__finditem__(akey); - if (bvalue == null) + if (bvalue == null) { return Py.False; + } PyObject avalue = __finditem__(akey); - if (!avalue._eq(bvalue).__nonzero__()) + if (!avalue._eq(bvalue).__nonzero__()) { return Py.False; + } } return Py.True; } - public PyObject __ne__(PyObject ob_other) { - return dict___ne__(ob_other); + @Override + public PyObject __ne__(PyObject otherObj) { + return dict___ne__(otherObj); } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___ne___doc) - final PyObject dict___ne__(PyObject ob_other) { - PyObject eq_result = __eq__(ob_other); - if (eq_result == null) return null; + final PyObject dict___ne__(PyObject otherObj) { + PyObject eq_result = __eq__(otherObj); + if (eq_result == null) { + return null; + } return eq_result.__not__(); } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___lt___doc) - final PyObject dict___lt__(PyObject ob_other){ - int result = __cmp__(ob_other); - if(result == -2){ + final PyObject dict___lt__(PyObject otherObj) { + int result = __cmp__(otherObj); + if (result == -2) { return null; } return result < 0 ? Py.True : Py.False; } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___gt___doc) - final PyObject dict___gt__(PyObject ob_other){ - int result = __cmp__(ob_other); - if(result == -2){ + final PyObject dict___gt__(PyObject otherObj) { + int result = __cmp__(otherObj); + if (result == -2) { return null; } return result > 0 ? Py.True : Py.False; } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___le___doc) - final PyObject dict___le__(PyObject ob_other){ - int result = __cmp__(ob_other); - if(result == -2){ + final PyObject dict___le__(PyObject otherObj) { + int result = __cmp__(otherObj); + if (result == -2) { return null; } return result <= 0 ? Py.True : Py.False; } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___ge___doc) - final PyObject dict___ge__(PyObject ob_other){ - int result = __cmp__(ob_other); - if(result == -2){ + final PyObject dict___ge__(PyObject otherObj) { + int result = __cmp__(otherObj); + if (result == -2) { return null; } return result >= 0 ? Py.True : Py.False; } - public int __cmp__(PyObject ob_other) { - return dict___cmp__(ob_other); + @Override + public int __cmp__(PyObject otherObj) { + return dict___cmp__(otherObj); } @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.dict___cmp___doc) - final int dict___cmp__(PyObject ob_other) { + final int dict___cmp__(PyObject otherObj) { PyType thisType = getType(); - PyType otherType = ob_other.getType(); + PyType otherType = otherObj.getType(); if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return -2; } - PyDictionary other = (PyDictionary)ob_other; + PyDictionary other = (PyDictionary)otherObj; int an = table.size(); int bn = other.table.size(); - if (an < bn) return -1; - if (an > bn) return 1; + if (an < bn) { + return -1; + } + if (an > bn) { + return 1; + } PyList akeys = keys(); PyList bkeys = other.keys(); @@ -305,26 +328,28 @@ akeys.sort(); bkeys.sort(); - for (int i=0; i<bn; i++) { + for (int i = 0; i < bn; i++) { PyObject akey = akeys.pyget(i); PyObject bkey = bkeys.pyget(i); int c = akey._cmp(bkey); - if (c != 0) + if (c != 0) { return c; + } PyObject avalue = __finditem__(akey); PyObject bvalue = other.__finditem__(bkey); - if(avalue == null){ - if(bvalue == null){ + if (avalue == null) { + if (bvalue == null) { continue; } return -3; - }else if(bvalue == null){ + } else if (bvalue == null) { return -3; } c = avalue._cmp(bvalue); - if (c != 0) + if (c != 0) { return c; + } } return 0; } @@ -341,6 +366,7 @@ return table.containsKey(key); } + @Override public boolean __contains__(PyObject o) { return dict___contains__(o); } @@ -351,24 +377,20 @@ } /** - * Return this[key] if the key exists in the mapping, default_object - * is returned otherwise. + * Return this[key] if the key exists in the mapping, defaultObj is returned + * otherwise. * - * @param key the key to lookup in the dictionary. - * @param default_object the value to return if the key does not - * exists in the mapping. + * @param key the key to lookup in the dictionary. + * @param defaultObj the value to return if the key does not exists in the mapping. */ - public PyObject get(PyObject key, PyObject default_object) { - return dict_get(key,default_object); + public PyObject get(PyObject key, PyObject defaultObj) { + return dict_get(key, defaultObj); } @ExposedMethod(defaults = "Py.None", doc = BuiltinDocs.dict_get_doc) - final PyObject dict_get(PyObject key, PyObject default_object) { + final PyObject dict_get(PyObject key, PyObject defaultObj) { PyObject o = table.get(key); - if (o == null) - return default_object; - else - return o; + return o == null ? defaultObj : o; } /** @@ -441,8 +463,8 @@ } } - private void merge(Map<Object,Object> other) { - for (Entry<Object,Object> entry : other.entrySet()) { + private void merge(Map<Object, Object> other) { + for (Entry<Object, Object> entry : other.entrySet()) { dict___setitem__(Py.java2py(entry.getKey()), Py.java2py(entry.getValue())); } } @@ -524,29 +546,21 @@ * if key does not already exist. */ public PyObject setdefault(PyObject key, PyObject failobj) { - return dict_setdefault(key,failobj); + return dict_setdefault(key, failobj); } //XXX: needs __doc__ but CPython does not define setdefault @ExposedMethod(defaults = "Py.None") final PyObject dict_setdefault(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); - if (oldValue == null) { - return failobj; - } else { - return oldValue; - } + return oldValue == null ? failobj : oldValue; } //XXX: needs __doc__ but CPython does not define setifabsent @ExposedMethod(defaults = "Py.None") final PyObject dict_setifabsent(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); - if (oldValue == null) { - return Py.None; - } else { - return oldValue; - } + return oldValue == null ? Py.None : oldValue; } @@ -589,8 +603,9 @@ @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { Iterator<Entry<PyObject, PyObject>> it = table.entrySet().iterator(); - if (!it.hasNext()) + if (!it.hasNext()) { throw Py.KeyError("popitem(): dictionary is empty"); + } Entry<PyObject, PyObject> entry = it.next(); PyTuple tuple = new PyTuple(entry.getKey(), entry.getValue()); it.remove(); @@ -667,6 +682,7 @@ return new ValuesIter(table.values()); } + @Override public int hashCode() { return dict___hash__(); } @@ -697,6 +713,7 @@ size = values.size(); } + @Override public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -719,6 +736,7 @@ size = items.size(); } + @Override public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -821,7 +839,11 @@ /** Basic implementation of Entry that just holds onto a key and value and returns them. */ class SimpleEntry implements Entry { - public SimpleEntry(Object key, Object value){ + protected Object key; + + protected Object value; + + public SimpleEntry(Object key, Object value) { this.key = key; this.value = value; } @@ -834,8 +856,9 @@ return value; } + @Override public boolean equals(Object o) { - if(!(o instanceof Map.Entry)) { + if (!(o instanceof Map.Entry)) { return false; } Map.Entry e = (Map.Entry)o; @@ -846,10 +869,12 @@ return o1 == null ? o2 == null : o1.equals(o2); } + @Override public int hashCode() { return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); } + @Override public String toString() { return key + "=" + value; } @@ -857,10 +882,6 @@ public Object setValue(Object val) { throw new UnsupportedOperationException("Not supported by this view"); } - - protected Object key; - - protected Object value; } /** @@ -877,18 +898,23 @@ super(entry.getKey(), entry.getValue()); } + @Override public boolean equals(Object o) { - if (o == null || !(o instanceof Entry)) return false; + if (o == null || !(o instanceof Entry)) { + return false; + } Entry me = new JavaToPyMapEntry((Entry)o); return o.equals(me); } // tojava is called in getKey and getValue so the raw key and value can be // used to create a new SimpleEntry in getEntry. + @Override public Object getKey() { return PyDictionary.tojava(key); } + @Override public Object getValue() { return PyDictionary.tojava(value); } @@ -923,10 +949,12 @@ super(coll); } + @Override Object toJava(Object o) { return PyDictionary.tojava(o); } + @Override Object toPython(Object o) { return Py.java2py(o); } @@ -948,9 +976,11 @@ // We know that PyMapEntrySet will only contains entries, so if the object being passed in is // null or not an Entry, then return null which will match nothing for remove and contains // methods. + @Override Object toPython(Object o) { - if(o == null || !(o instanceof Entry)) + if (o == null || !(o instanceof Entry)) { return null; + } if (o instanceof PyToJavaMapEntry) { // Use the original entry from PyDictionary return ((PyToJavaMapEntry)o).getEntry(); @@ -959,6 +989,7 @@ } } + @Override Object toJava(Object o) { return new PyToJavaMapEntry((Entry)o); } @@ -975,6 +1006,8 @@ */ abstract class PyMapSet extends AbstractSet { + private final Collection coll; + PyMapSet(Collection coll) { this.coll = coll; } @@ -983,18 +1016,22 @@ abstract Object toPython(Object obj); + @Override public int size() { return coll.size(); } + @Override public boolean contains(Object o) { return coll.contains(toPython(o)); } + @Override public boolean remove(Object o) { return coll.remove(toPython(o)); } + @Override public void clear() { coll.clear(); } @@ -1022,9 +1059,8 @@ } } + @Override public Iterator iterator() { return new PySetIter(coll.iterator()); } - - private final Collection coll; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-29 02:53:23
|
Revision: 6927 http://jython.svn.sourceforge.net/jython/?rev=6927&view=rev Author: pjenvey Date: 2009-10-29 02:53:00 +0000 (Thu, 29 Oct 2009) Log Message: ----------- dict doesn't need __nonzero__ exposed, doc setdefault Modified Paths: -------------- trunk/jython/src/org/python/core/PyDictionary.java Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2009-10-28 23:41:45 UTC (rev 6926) +++ trunk/jython/src/org/python/core/PyDictionary.java 2009-10-29 02:53:00 UTC (rev 6927) @@ -116,12 +116,6 @@ @Override public boolean __nonzero__() { - return dict___nonzero__(); - } - - //XXX: CPython's dict does not define __nonzero__ - @ExposedMethod - final boolean dict___nonzero__() { return table.size() != 0; } @@ -549,14 +543,13 @@ return dict_setdefault(key, failobj); } - //XXX: needs __doc__ but CPython does not define setdefault - @ExposedMethod(defaults = "Py.None") + @ExposedMethod(defaults = "Py.None", doc = BuiltinDocs.dict_setdefault_doc) final PyObject dict_setdefault(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); return oldValue == null ? failobj : oldValue; } - //XXX: needs __doc__ but CPython does not define setifabsent + // XXX: needs __doc__ but CPython does not define setifabsent @ExposedMethod(defaults = "Py.None") final PyObject dict_setifabsent(PyObject key, PyObject failobj) { PyObject oldValue = table.putIfAbsent(key, failobj); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-29 04:28:09
|
Revision: 6929 http://jython.svn.sourceforge.net/jython/?rev=6929&view=rev Author: pjenvey Date: 2009-10-29 04:28:03 +0000 (Thu, 29 Oct 2009) Log Message: ----------- avoid unnecessary copying when creating lists Modified Paths: -------------- trunk/jython/src/org/python/core/PyDictionary.java Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2009-10-29 04:26:36 UTC (rev 6928) +++ trunk/jython/src/org/python/core/PyDictionary.java 2009-10-29 04:28:03 UTC (rev 6929) @@ -619,7 +619,7 @@ for (Entry<PyObject, PyObject> entry : table.entrySet()) { list.add(new PyTuple(entry.getKey(), entry.getValue())); } - return new PyList(list); + return PyList.fromList(list); } /** @@ -631,12 +631,12 @@ @ExposedMethod(doc = BuiltinDocs.dict_keys_doc) final PyList dict_keys() { - return new PyList(new ArrayList<PyObject>(table.keySet())); + return PyList.fromList(new ArrayList<PyObject>(table.keySet())); } @ExposedMethod(doc = BuiltinDocs.dict_values_doc) final PyList dict_values() { - return new PyList(new ArrayList<PyObject>(table.values())); + return PyList.fromList(new ArrayList<PyObject>(table.values())); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |