From: <zy...@us...> - 2008-12-19 07:14:01
|
Revision: 5780 http://jython.svn.sourceforge.net/jython/?rev=5780&view=rev Author: zyasoft Date: 2008-12-19 07:13:56 +0000 (Fri, 19 Dec 2008) Log Message: ----------- For org.python.core and modules: * Replaced Vector and Hashtable with ArrayList and HashMap respectively. * Converted StringBuffer to StringBuilder where thread confined. Modified Paths: -------------- trunk/jython/src/org/python/core/AbstractArray.java trunk/jython/src/org/python/core/BaseSet.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyDictionary.java trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PyInstance.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyStringMap.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/PyTraceback.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java trunk/jython/src/org/python/modules/_collections/PyDeque.java trunk/jython/src/org/python/modules/_weakref/GlobalRef.java trunk/jython/src/org/python/modules/binascii.java trunk/jython/src/org/python/modules/cPickle.java trunk/jython/src/org/python/modules/sre/PatternObject.java trunk/jython/src/org/python/modules/time/Time.java trunk/jython/src/org/python/modules/ucnhash.java Modified: trunk/jython/src/org/python/core/AbstractArray.java =================================================================== --- trunk/jython/src/org/python/core/AbstractArray.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/AbstractArray.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -533,7 +533,7 @@ * @see java.lang.Object#toString() */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("["); Object base = getArray(); Modified: trunk/jython/src/org/python/core/BaseSet.java =================================================================== --- trunk/jython/src/org/python/core/BaseSet.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/BaseSet.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -387,7 +387,7 @@ if (!ts.enterRepr(this)) { return name + "(...)"; } - StringBuffer buf = new StringBuffer(name).append("(["); + StringBuilder buf = new StringBuilder(name).append("(["); for (Iterator i = _set.iterator(); i.hasNext();) { buf.append(((PyObject)i.next()).__repr__().toString()); if (i.hasNext()) { Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/Py.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -1056,7 +1056,7 @@ } static String formatException(PyObject type, PyObject value, PyObject tb) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); if (PyException.isExceptionClass(type)) { String className = PyException.exceptionClassName(type); Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyDictionary.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -187,7 +187,7 @@ return "{...}"; } - StringBuffer buf = new StringBuffer("{"); + StringBuilder buf = new StringBuilder("{"); for (Entry<PyObject, PyObject> entry : table.entrySet()) { buf.append((entry.getKey()).__repr__().toString()); Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyFile.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -490,7 +490,7 @@ @ExposedMethod(names = {"__str__", "__repr__"}) final String file_toString() { - StringBuffer s = new StringBuffer("<"); + StringBuilder s = new StringBuilder("<"); if (file.closed()) { s.append("closed "); } else { Modified: trunk/jython/src/org/python/core/PyInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyInstance.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyInstance.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -1,6 +1,5 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.util.Hashtable; /** * A python class instance. @@ -76,8 +75,6 @@ public PyInstance() {} - private static Hashtable primitiveMap; - public Object __tojava__(Class c) { if (c.isInstance(this)) return this; Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyList.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -417,7 +417,7 @@ if(!ts.enterRepr(this)) { return "[...]"; } - StringBuffer buf = new StringBuffer("["); + StringBuilder buf = new StringBuilder("["); int length = size(); PyObject[] array = getArray(); for(int i = 0; i < length - 1; i++) { Modified: trunk/jython/src/org/python/core/PyStringMap.java =================================================================== --- trunk/jython/src/org/python/core/PyStringMap.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyStringMap.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -131,7 +131,7 @@ if (!ts.enterRepr(this)) { return "{...}"; } - StringBuffer buf = new StringBuffer("{"); + StringBuilder buf = new StringBuilder("{"); for (Entry<Object, PyObject> entry : table.entrySet()) { Object key = entry.getKey(); if (key instanceof String) { Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -7,8 +7,7 @@ import java.net.URL; import java.net.URLDecoder; import java.security.AccessControlException; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; @@ -72,7 +71,7 @@ "Amsterdam.\n" + "All Rights Reserved.\n\n"); - private static Hashtable builtinNames; + private static Map<String,String> builtinNames; public static PyTuple builtin_module_names = null; public static PackageManager packageManager; @@ -160,22 +159,13 @@ __displayhook__ = new PySystemStateFunctions("displayhook", 10, 1, 1); __excepthook__ = new PySystemStateFunctions("excepthook", 30, 3, 3); - // This isn't quite right... if(builtins == null){ builtins = new PyStringMap(); __builtin__.fillWithBuiltins(builtins); } PyModule __builtin__ = new PyModule("__builtin__", builtins); modules.__setitem__("__builtin__", __builtin__); - __dict__ = new PyStringMap(); - - // This isn't right either, because __dict__ can be directly - // accessed from Python, for example: - // - // >>> sys.__dict__['settrace'] - // <java function settrace 81> - __dict__.invoke("update", getType().fastGetDict()); __dict__.__setitem__("displayhook", __displayhook__); __dict__.__setitem__("excepthook", __excepthook__); @@ -707,7 +697,7 @@ } private static void initBuiltins(Properties props) { - builtinNames = new Hashtable(); + builtinNames = new HashMap<String,String>(); // add the oddball builtins that are specially handled builtinNames.put("__builtin__", ""); @@ -724,10 +714,11 @@ addBuiltin(tok.nextToken()); int n = builtinNames.size(); - PyObject [] built_mod = new PyObject[n]; - Enumeration keys = builtinNames.keys(); - for (int i=0; i<n; i++) - built_mod[i] = Py.newString((String)keys.nextElement()); + PyObject [] built_mod = new PyObject[n]; + int i = 0; + for (String key : builtinNames.keySet()) { + built_mod[i++] = Py.newString(key); + } builtin_module_names = new PyTuple(built_mod); } Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -101,7 +101,7 @@ return line; } - public void dumpStack(StringBuffer buf) { + public void dumpStack(StringBuilder buf) { buf.append(tracebackInfo()); if (tb_next != Py.None && tb_next != this) { ((PyTraceback)tb_next).dumpStack(buf); @@ -111,7 +111,7 @@ } public String dumpStack() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("Traceback (most recent call last):\n"); dumpStack(buf); return buf.toString(); Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyTuple.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -272,7 +272,7 @@ @ExposedMethod final String tuple___repr__() { - StringBuffer buf = new StringBuffer("("); + StringBuilder buf = new StringBuilder("("); PyObject[] array = getArray(); int arrayLen = size(); for (int i = 0; i < arrayLen-1; i++) { Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/PyType.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -651,7 +651,7 @@ } private static PyException mro_error(PyObject[][] to_merge, int[] remain) { - StringBuffer msg = new StringBuffer("Cannot create a consistent method resolution\n" + StringBuilder msg = new StringBuilder("Cannot create a consistent method resolution\n" + "order (MRO) for bases "); PyDictionary set = new PyDictionary(); for (int i = 0; i < to_merge.length; i++) { Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/imp.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -503,7 +503,7 @@ * @return the loaded module */ public static PyObject load(String name) { - return import_first(name, new StringBuffer()); + return import_first(name, new StringBuilder()); } /** @@ -560,7 +560,7 @@ * @return null or None */ private static PyObject import_next(PyObject mod, - StringBuffer parentNameBuffer, String name, String outerFullName, PyObject fromlist) { + StringBuilder parentNameBuffer, String name, String outerFullName, PyObject fromlist) { if (parentNameBuffer.length() > 0) { parentNameBuffer.append('.'); } @@ -594,7 +594,7 @@ // never returns null or None private static PyObject import_first(String name, - StringBuffer parentNameBuffer) { + StringBuilder parentNameBuffer) { PyObject ret = import_next(null, parentNameBuffer, name, null, null); if (ret == null || ret == Py.None) { throw Py.ImportError("No module named " + name); @@ -603,7 +603,7 @@ } - private static PyObject import_first(String name, StringBuffer parentNameBuffer, String fullName, PyObject fromlist) { + private static PyObject import_first(String name, StringBuilder parentNameBuffer, String fullName, PyObject fromlist) { PyObject ret = import_next(null, parentNameBuffer, name, fullName, fromlist); if (ret == null || ret == Py.None) { if (JavaImportHelper.tryAddPackage(fullName, fromlist)) { @@ -621,7 +621,7 @@ // never returns null or None // ??pending: check if result is really a module/jpkg/jclass? private static PyObject import_logic(PyObject mod, - StringBuffer parentNameBuffer, String dottedName, String fullName, PyObject fromlist) { + StringBuilder parentNameBuffer, String dottedName, String fullName, PyObject fromlist) { int dot = 0; int last_dot = 0; @@ -673,7 +673,7 @@ } else { firstName = name.substring(0, dot); } - StringBuffer parentNameBuffer = new StringBuffer(pkgMod != null ? pkgName : ""); + StringBuilder parentNameBuffer = new StringBuilder(pkgMod != null ? pkgName : ""); PyObject topMod = import_next(pkgMod, parentNameBuffer, firstName, name, fromlist); if (topMod == Py.None || topMod == null) { // Add None to sys.modules for submodule or subpackage names that aren't found, but @@ -682,7 +682,7 @@ if (topMod == null && pkgMod != null) { modules.__setitem__(parentNameBuffer.toString().intern(), Py.None); } - parentNameBuffer = new StringBuffer(""); + parentNameBuffer = new StringBuilder(""); // could throw ImportError topMod = import_first(firstName, parentNameBuffer, name, fromlist); } @@ -697,7 +697,7 @@ } if (fromlist != null && fromlist != Py.None) { - StringBuffer modNameBuffer = new StringBuffer(name); + StringBuilder modNameBuffer = new StringBuilder(name); for (PyObject submodName : fromlist.asIterable()) { if (mod.__findattr__(submodName.toString()) != null || submodName.toString().equals("*")) { Modified: trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -20,8 +20,11 @@ import java.net.URLConnection; import java.security.AccessControlException; import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; +import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -95,13 +98,13 @@ private boolean indexModified; - private Hashtable jarfiles; + private Map<String,JarXEntry> jarfiles; - private static String vectorToString(Vector vec) { + private static String vectorToString(List vec) { int n = vec.size(); - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); for (int i = 0; i < n; i++) { - ret.append((String) vec.elementAt(i)); + ret.append((String) vec.get(i)); if (i < n - 1) { ret.append(","); } @@ -111,7 +114,7 @@ // Add a single class from zipFile to zipPackages // Only add valid, public classes - private void addZipEntry(Hashtable zipPackages, ZipEntry entry, + private void addZipEntry(Map zipPackages, ZipEntry entry, ZipInputStream zip) throws IOException { String name = entry.getName(); // System.err.println("entry: "+name); @@ -139,22 +142,22 @@ return; } - Vector[] vec = (Vector[]) zipPackages.get(packageName); + List[] vec = (List[]) zipPackages.get(packageName); if (vec == null) { - vec = new Vector[] { new Vector(), new Vector() }; + vec = new ArrayList[] { new ArrayList(), new ArrayList() }; zipPackages.put(packageName, vec); } int access = checkAccess(zip); if ((access != -1) && !filterByAccess(name, access)) { - vec[0].addElement(className); + vec[0].add(className); } else { - vec[1].addElement(className); + vec[1].add(className); } } // Extract all of the packages in a single jarfile - private Hashtable getZipPackages(InputStream jarin) throws IOException { - Hashtable zipPackages = new Hashtable(); + private Map getZipPackages(InputStream jarin) throws IOException { + Map zipPackages = new HashMap(); ZipInputStream zip = new ZipInputStream(jarin); @@ -165,9 +168,8 @@ } // Turn each vector into a comma-separated String - for (Enumeration e = zipPackages.keys(); e.hasMoreElements();) { - Object key = e.nextElement(); - Vector[] vec = (Vector[]) zipPackages.get(key); + for (Object key : zipPackages.keySet()) { + List[] vec = (List[]) zipPackages.get(key); String classes = vectorToString(vec[0]); if (vec[1].size() > 0) { classes += '@' + vectorToString(vec[1]); @@ -245,7 +247,7 @@ return; } - Hashtable zipPackages = null; + Map zipPackages = null; long mtime = 0; String jarcanon = null; @@ -327,10 +329,10 @@ } - private void addPackages(Hashtable zipPackages, String jarfile) { - for (Enumeration e = zipPackages.keys(); e.hasMoreElements();) { - String pkg = (String) e.nextElement(); - String classes = (String) zipPackages.get(pkg); + private void addPackages(Map<String,String> zipPackages, String jarfile) { + for (Entry<String,String> entry : zipPackages.entrySet()) { + String pkg = entry.getKey(); + String classes = entry.getValue(); int idx = classes.indexOf('@'); if (idx >= 0 && Options.respectJavaAccessibility) { @@ -343,7 +345,7 @@ // Read in cache file storing package info for a single .jar // Return null and delete this cachefile if it is invalid - private Hashtable readCacheFile(JarXEntry entry, String jarcanon) { + private Map readCacheFile(JarXEntry entry, String jarcanon) { String cachefile = entry.cachefile; long mtime = entry.mtime; @@ -359,7 +361,7 @@ deleteCacheFile(cachefile); return null; } - Hashtable packs = new Hashtable(); + Map packs = new HashMap(); try { while (true) { String packageName = istream.readUTF(); @@ -380,16 +382,15 @@ // Write a cache file storing package info for a single .jar private void writeCacheFile(JarXEntry entry, String jarcanon, - Hashtable zipPackages, boolean brandNew) { + Map<String,String> zipPackages, boolean brandNew) { try { DataOutputStream ostream = outCreateCacheFile(entry, brandNew); ostream.writeUTF(jarcanon); ostream.writeLong(entry.mtime); comment("rewriting cachefile for '" + jarcanon + "'"); - for (Enumeration e = zipPackages.keys(); e.hasMoreElements();) { - String packageName = (String) e.nextElement(); - String classes = (String) zipPackages.get(packageName); + for (String packageName : zipPackages.keySet()) { + String classes = zipPackages.get(packageName); ostream.writeUTF(packageName); ostream.writeUTF(classes); } @@ -405,7 +406,7 @@ */ protected void initCache() { this.indexModified = false; - this.jarfiles = new Hashtable(); + this.jarfiles = new HashMap(); try { DataInputStream istream = inOpenIndex(); @@ -436,22 +437,22 @@ * outOpenIndex(). */ public void saveCache() { - if (this.jarfiles == null || !this.indexModified) { + if (jarfiles == null || !indexModified) { return; } - this.indexModified = false; + indexModified = false; comment("writing modified index file"); try { DataOutputStream ostream = outOpenIndex(); - for (Enumeration e = this.jarfiles.keys(); e.hasMoreElements();) { - String jarcanon = (String) e.nextElement(); - JarXEntry entry = (JarXEntry) this.jarfiles.get(jarcanon); + for (Entry<String,JarXEntry> entry : jarfiles.entrySet()) { + String jarcanon = entry.getKey(); + JarXEntry xentry = entry.getValue(); ostream.writeUTF(jarcanon); - ostream.writeUTF(entry.cachefile); - ostream.writeLong(entry.mtime); + ostream.writeUTF(xentry.cachefile); + ostream.writeLong(xentry.mtime); } ostream.close(); } catch (IOException ioe) { Modified: trunk/jython/src/org/python/modules/_collections/PyDeque.java =================================================================== --- trunk/jython/src/org/python/modules/_collections/PyDeque.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/_collections/PyDeque.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -228,7 +228,7 @@ if (!ts.enterRepr(this)) { return "[...]"; } - StringBuffer buf = new StringBuffer("deque").append("(["); + StringBuilder buf = new StringBuilder("deque").append("(["); for (Node tmp = header.right; tmp != header; tmp = tmp.right) { buf.append(tmp.data.__repr__().toString()); if (tmp.right != header) { Modified: trunk/jython/src/org/python/modules/_weakref/GlobalRef.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -4,9 +4,10 @@ import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.Vector; +import java.util.List; import org.python.core.Py; import org.python.core.PyException; @@ -20,7 +21,7 @@ /** Whether the hash value was calculated by the underlying object. */ boolean realHash; - private Vector references = new Vector(); + private List references = new ArrayList(); private static ReferenceQueue referenceQueue = new ReferenceQueue(); @@ -59,11 +60,11 @@ public synchronized void add(AbstractReference ref) { Reference r = new WeakReference(ref); - references.addElement(r); + references.add(r); } private final AbstractReference getReferenceAt(int idx) { - WeakReference wref = (WeakReference)references.elementAt(idx); + WeakReference wref = (WeakReference)references.get(idx); return (AbstractReference)wref.get(); } @@ -75,7 +76,7 @@ for (int i = references.size() - 1; i >= 0; i--) { AbstractReference r = getReferenceAt(i); if (r == null) { - references.removeElementAt(i); + references.remove(i); } else if (r.callback == null && r.getClass() == cls) { return r; } @@ -90,7 +91,7 @@ for (int i = references.size() - 1; i >= 0; i--) { AbstractReference r = getReferenceAt(i); if (r == null) { - references.removeElementAt(i); + references.remove(i); } else { r.call(); } @@ -101,20 +102,20 @@ for (int i = references.size() - 1; i >= 0; i--) { AbstractReference r = getReferenceAt(i); if (r == null) { - references.removeElementAt(i); + references.remove(i); } } return references.size(); } synchronized public PyList refs() { - Vector list = new Vector(); + List list = new ArrayList(); for (int i = references.size() - 1; i >= 0; i--) { AbstractReference r = getReferenceAt(i); if (r == null) { - references.removeElementAt(i); + references.remove(i); } else { - list.addElement(r); + list.add(r); } } return new PyList(list); Modified: trunk/jython/src/org/python/modules/binascii.java =================================================================== --- trunk/jython/src/org/python/modules/binascii.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/binascii.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -279,7 +279,7 @@ if (ascii_data.length() == 0) return new PyString(""); - StringBuffer bin_data = new StringBuffer(); + StringBuilder bin_data = new StringBuilder(); char this_ch; int i; @@ -357,7 +357,7 @@ throw new PyException(Error, "At most 45 bytes at once"); } - StringBuffer ascii_data = new StringBuffer(); + StringBuilder ascii_data = new StringBuilder(); // Store the length */ ascii_data.append((char)(' ' + (bin_len & 077))); @@ -426,7 +426,7 @@ int ascii_len = ascii_data.length(); int bin_len = 0; - StringBuffer bin_data = new StringBuffer(); + StringBuilder bin_data = new StringBuilder(); for(int i = 0; ascii_len > 0 ; ascii_len--, i++) { // Skip some punctuation @@ -487,7 +487,7 @@ char this_ch; int leftchar = 0; - StringBuffer ascii_data = new StringBuffer(); + StringBuilder ascii_data = new StringBuilder(); int bin_len = bin_data.length(); if (bin_len > BASE64_MAXBIN) { @@ -539,7 +539,7 @@ int len = ascii_data.length(); - StringBuffer bin_data = new StringBuffer(); + StringBuilder bin_data = new StringBuilder(); for(int i = 0; len > 0 ; len--, i++) { // Get the byte and look it up @@ -585,7 +585,7 @@ static public String rlecode_hqx(String in_data) { int len = in_data.length(); - StringBuffer out_data = new StringBuffer(); + StringBuilder out_data = new StringBuilder(); for (int in=0; in < len; in++) { char ch = in_data.charAt(in); @@ -632,7 +632,7 @@ int len = bin_data.length(); - StringBuffer ascii_data = new StringBuffer(); + StringBuilder ascii_data = new StringBuilder(); for(int i = 0; len > 0; len--, i++) { // Shift into our buffer, and output any 6bits ready @@ -677,7 +677,7 @@ if (in_len == 0) return ""; - StringBuffer out_data = new StringBuffer(); + StringBuilder out_data = new StringBuilder(); // Handle first byte separately (since we have to get angry // in case of an orphaned RLE code). @@ -837,7 +837,7 @@ public static PyString b2a_hex(String argbuf) { int arglen = argbuf.length(); - StringBuffer retbuf = new StringBuffer(arglen*2); + StringBuilder retbuf = new StringBuilder(arglen*2); /* make hex version of string, taken from shamodule.c */ for (int i = 0; i < arglen; i++) { @@ -874,7 +874,7 @@ if (arglen % 2 != 0) throw Py.TypeError("Odd-length string"); - StringBuffer retbuf = new StringBuffer(arglen/2); + StringBuilder retbuf = new StringBuilder(arglen/2); for (int i = 0; i < arglen; i += 2) { int top = Character.digit(argbuf.charAt(i), 16); @@ -893,7 +893,7 @@ final private static char[] upper_hexdigit = "0123456789ABCDEF".toCharArray(); - private static StringBuffer qpEscape(StringBuffer sb, char c) + private static StringBuilder qpEscape(StringBuilder sb, char c) { sb.append('='); sb.append(upper_hexdigit[(c >>> 4) & 0xF]); @@ -921,7 +921,7 @@ { ArgParser ap = new ArgParser("a2b_qp", arg, kws, new String[] {"s", "header"}); String s = ap.getString(0); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); boolean header = getIntFlagAsBool(ap, 1, 0, "an integer is required"); if (header) @@ -979,7 +979,7 @@ lineEnd = "\n"; s = RN_TO_N.matcher(s).replaceAll("\n"); } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int count = 0; for (int i=0, m=s.length(); i<m; i++) { char c = s.charAt(i); Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/cPickle.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -13,7 +13,8 @@ package org.python.modules; import java.math.BigInteger; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; import org.python.core.ClassDictInit; import org.python.core.Py; @@ -746,7 +747,7 @@ // Use any python object as a file. static class ObjectIOFile implements IOFile { char[] charr = new char[1]; - StringBuffer buff = new StringBuffer(); + StringBuilder buff = new StringBuilder(); PyObject write; PyObject read; PyObject readline; @@ -1514,12 +1515,12 @@ - private static Hashtable classmap = new Hashtable(); + private static Map<PyObject,PyObject> classmap = new HashMap<PyObject,PyObject>(); final private static PyObject whichmodule(PyObject cls, PyObject clsname) { - PyObject name = (PyObject)classmap.get(cls); + PyObject name = classmap.get(cls); if (name != null) return name; @@ -1704,7 +1705,7 @@ private IOFile file; - public Hashtable memo = new Hashtable(); + public Map<String,PyObject> memo = new HashMap<String,PyObject>(); /** * For the benefit of persistency modules written using pickle, @@ -2193,7 +2194,7 @@ final private void load_get() { String py_str = file.readlineNoNl(); - PyObject value = (PyObject)memo.get(py_str); + PyObject value = memo.get(py_str); if (value == null) throw new PyException(BadPickleGet, py_str); push(value); @@ -2201,7 +2202,7 @@ final private void load_binget() { String py_key = String.valueOf((int)file.read(1).charAt(0)); - PyObject value = (PyObject)memo.get(py_key); + PyObject value = memo.get(py_key); if (value == null) throw new PyException(BadPickleGet, py_key); push(value); @@ -2210,7 +2211,7 @@ final private void load_long_binget() { int i = read_binint(); String py_key = String.valueOf(i); - PyObject value = (PyObject)memo.get(py_key); + PyObject value = memo.get(py_key); if (value == null) throw new PyException(BadPickleGet, py_key); push(value); Modified: trunk/jython/src/org/python/modules/sre/PatternObject.java =================================================================== --- trunk/jython/src/org/python/modules/sre/PatternObject.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/sre/PatternObject.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -246,7 +246,7 @@ SRE_STATE state = new SRE_STATE(string, start, end, flags); - Vector list = new Vector(); + final List list = new ArrayList(); while (state.start <= state.end) { state.state_reset(); @@ -271,7 +271,7 @@ break; } - list.addElement(item); + list.add(item); if (state.ptr == state.start) state.start = state.ptr + 1; Modified: trunk/jython/src/org/python/modules/time/Time.java =================================================================== --- trunk/jython/src/org/python/modules/time/Time.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/time/Time.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -411,7 +411,7 @@ } public static PyString asctime(PyTuple tup) { - StringBuffer buf = new StringBuffer(25); + StringBuilder buf = new StringBuilder(25); buf.append(enshortdays[item(tup, 6)]).append(' '); buf.append(enshortmonths[item(tup, 1)]).append(' '); int dayOfMonth = item(tup, 2); Modified: trunk/jython/src/org/python/modules/ucnhash.java =================================================================== --- trunk/jython/src/org/python/modules/ucnhash.java 2008-12-19 06:00:48 UTC (rev 5779) +++ trunk/jython/src/org/python/modules/ucnhash.java 2008-12-19 07:13:56 UTC (rev 5780) @@ -163,7 +163,7 @@ int end = worddata.length; if (idx < wordoffs.length-1) end = wordoffs[idx+1]; - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int i = offset; i < end; i++) buf.append(charmap[worddata[i]]); return buf.toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |