From: <zy...@us...> - 2009-03-08 04:34:28
|
Revision: 6085 http://jython.svn.sourceforge.net/jython/?rev=6085&view=rev Author: zyasoft Date: 2009-03-08 04:34:13 +0000 (Sun, 08 Mar 2009) Log Message: ----------- PyStringMap#setdefault should use putIfAbsent, just like PyDictionary#setdefault. Fixes #735205. Modified Paths: -------------- trunk/jython/src/org/python/core/PyStringMap.java Modified: trunk/jython/src/org/python/core/PyStringMap.java =================================================================== --- trunk/jython/src/org/python/core/PyStringMap.java 2009-03-08 04:10:37 UTC (rev 6084) +++ trunk/jython/src/org/python/core/PyStringMap.java 2009-03-08 04:34:13 UTC (rev 6085) @@ -7,6 +7,7 @@ import java.util.Set; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; /** * Special fast dict implementation for __dict__ instances. Allows interned String keys in addition @@ -14,7 +15,7 @@ */ public class PyStringMap extends PyObject { - private final Map<Object, PyObject> table; + private final ConcurrentMap<Object, PyObject> table; public PyStringMap() { this(4); @@ -334,11 +335,13 @@ * the default value to insert in the mapping if key does not already exist. */ public PyObject setdefault(PyObject key, PyObject failobj) { - PyObject o = __finditem__(key); - if (o == null) { - __setitem__(key, o = failobj); + Object internedKey = (key instanceof PyString) ? ((PyString)key).internedString() : key; + PyObject oldValue = table.putIfAbsent(internedKey, failobj); + if (oldValue == null) { + return failobj; + } else { + return oldValue; } - return o; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |