Permalink
Browse files

StringBuffer -> StringBuilder (Local objects, no concurrency)

  • Loading branch information...
sgothel committed Apr 15, 2012
1 parent 94863d2 commit 900b2a73b2d0b6f934718ac88015151c5bf7ccb8
@@ -542,7 +542,7 @@ public static URL getRelativeOf(URL baseLocation, String relativeFile) throws Ma
}
public static URL compose(String scheme, String auth, String path1, String path2, String query, String fragment) throws MalformedURLException {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if(null!=scheme) {
sb.append(scheme);
sb.append(":");
@@ -94,7 +94,7 @@ public static final boolean isClassAvailable(String clazzName, ClassLoader cl) {
}
static final String asString(Class<?>[] argTypes) {
- StringBuffer args = new StringBuffer();
+ StringBuilder args = new StringBuilder();
boolean coma = false;
if(null != argTypes) {
for (int i = 0; i < argTypes.length; i++) {
@@ -1090,7 +1090,7 @@ protected String jniMangle(String name) {
}
protected String jniMangle(MethodBinding binding) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append(jniMangle(getName()));
buf.append(getImplSuffix());
buf.append("__");
@@ -1147,7 +1147,7 @@ protected String jniMangle(MethodBinding binding) {
return buf.toString();
}
- protected void jniMangle(Class<?> c, StringBuffer res, boolean syntheticArgument) {
+ protected void jniMangle(Class<?> c, StringBuilder res, boolean syntheticArgument) {
if (c.isPrimitive()) {
if (c == Boolean.TYPE) res.append("Z");
else if (c == Byte.TYPE) res.append("B");
@@ -62,7 +62,7 @@ public TypeInfo(String name, int pointerDepth, JavaType javaType) {
@Override
public String toString() {
- StringBuffer buf = new StringBuffer("TypeInfo: ");
+ StringBuilder buf = new StringBuilder("TypeInfo: ");
buf.append(name);
buf.append(" pointerDepth ");
buf.append(pointerDepth);
@@ -5,18 +5,17 @@
import java.util.Enumeration;
-
public class CSymbolTable {
/** holds list of scopes */
- private Vector scopeStack;
+ private Vector<String> scopeStack;
/** table where all defined names are mapped to TNode tree nodes */
- private Hashtable symTable;
+ private Hashtable<String, TNode> symTable;
public CSymbolTable() {
- scopeStack = new Vector(10);
- symTable = new Hashtable(533);
+ scopeStack = new Vector<String>(10);
+ symTable = new Hashtable<String, TNode>(533);
}
@@ -39,9 +38,9 @@ public void popScope() {
/** return the current scope as a string
*/
public String currentScopeAsString() {
- StringBuffer buf = new StringBuffer(100);
+ StringBuilder buf = new StringBuilder(100);
boolean first = true;
- Enumeration e = scopeStack.elements();
+ Enumeration<String> e = scopeStack.elements();
while(e.hasMoreElements()) {
if(first)
first = false;
@@ -85,13 +84,13 @@ public String removeOneLevelScope(String scopeName) {
/** add a node to the table with it's key as
the current scope and the name */
public TNode add(String name, TNode node) {
- return (TNode)symTable.put(addCurrentScopeToName(name),node);
+ return symTable.put(addCurrentScopeToName(name),node);
}
/** lookup a fully scoped name in the symbol table */
public TNode lookupScopedName(String scopedName) {
- return (TNode)symTable.get(scopedName);
+ return symTable.get(scopedName);
}
/** lookup an unscoped name in the table by prepending
@@ -108,19 +107,19 @@ public TNode lookupNameInCurrentScope(String name) {
while (tnode == null && scope != null) {
scopedName = addScopeToName(scope, name);
//System.out.println("lookup trying " + scopedName);
- tnode = (TNode)symTable.get(scopedName);
+ tnode = symTable.get(scopedName);
scope = removeOneLevelScope(scope);
}
return tnode;
}
/** convert this table to a string */
public String toString() {
- StringBuffer buff = new StringBuffer(300);
+ StringBuilder buff = new StringBuilder(300);
buff.append("CSymbolTable { \nCurrentScope: " + currentScopeAsString() +
"\nDefinedSymbols:\n");
- Enumeration ke = symTable.keys();
- Enumeration ve = symTable.elements();
+ Enumeration<String> ke = symTable.keys();
+ Enumeration<TNode> ve = symTable.elements();
while(ke.hasMoreElements()) {
buff.append(ke.nextElement().toString() + " (" +
TNode.getNameForType(((TNode)ve.nextElement()).getType()) + ")\n");
@@ -106,8 +106,8 @@ public boolean getTreatAsC()
}
public String toString() {
- StringBuffer ret;
- ret = new StringBuffer("# " + line + " \"" + source + "\"");
+ StringBuilder ret;
+ ret = new StringBuilder("# " + line + " \"" + source + "\"");
if (enteringFile) {
ret.append(" 1");
}
@@ -4,18 +4,18 @@
public class PreprocessorInfoChannel
{
- Hashtable lineLists = new Hashtable(); // indexed by Token number
+ Hashtable<Integer, Vector<Object>> lineLists = new Hashtable<Integer, Vector<Object>>(); // indexed by Token number
int firstValidTokenNumber = 0;
int maxTokenNumber = 0;
public void addLineForTokenNumber( Object line, Integer toknum )
{
if ( lineLists.containsKey( toknum ) ) {
- Vector lines = (Vector) lineLists.get( toknum );
+ Vector<Object> lines = lineLists.get( toknum );
lines.addElement(line);
}
else {
- Vector lines = new Vector();
+ Vector<Object> lines = new Vector<Object>();
lines.addElement(line);
lineLists.put(toknum, lines);
if ( maxTokenNumber < toknum.intValue() ) {
@@ -29,16 +29,16 @@ public int getMaxTokenNumber()
return maxTokenNumber;
}
- public Vector extractLinesPrecedingTokenNumber( Integer toknum )
+ public Vector<Object> extractLinesPrecedingTokenNumber( Integer toknum )
{
- Vector lines = new Vector();
+ Vector<Object> lines = new Vector<Object>();
if (toknum == null) return lines;
for (int i = firstValidTokenNumber; i < toknum.intValue(); i++){
Integer inti = new Integer(i);
if ( lineLists.containsKey( inti ) ) {
- Vector tokenLineVector = (Vector) lineLists.get( inti );
+ Vector<Object> tokenLineVector = lineLists.get( inti );
if ( tokenLineVector != null) {
- Enumeration tokenLines = tokenLineVector.elements();
+ Enumeration<Object> tokenLines = tokenLineVector.elements();
while ( tokenLines.hasMoreElements() ) {
lines.addElement( tokenLines.nextElement() );
}
@@ -52,13 +52,13 @@ public Vector extractLinesPrecedingTokenNumber( Integer toknum )
public String toString()
{
- StringBuffer sb = new StringBuffer("PreprocessorInfoChannel:\n");
+ StringBuilder sb = new StringBuilder("PreprocessorInfoChannel:\n");
for (int i = 0; i <= maxTokenNumber + 1; i++){
Integer inti = new Integer(i);
if ( lineLists.containsKey( inti ) ) {
- Vector tokenLineVector = (Vector) lineLists.get( inti );
+ Vector<Object> tokenLineVector = lineLists.get( inti );
if ( tokenLineVector != null) {
- Enumeration tokenLines = tokenLineVector.elements();
+ Enumeration<Object> tokenLines = tokenLineVector.elements();
while ( tokenLines.hasMoreElements() ) {
sb.append(inti + ":" + tokenLines.nextElement() + '\n');
}
@@ -155,7 +155,7 @@ public void setText(String text_) {
/** Returns the text for this node and all children */
public String getAllChildrenText() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append(getText());
for (TNode node = (TNode) getFirstChild(); node != null; node = (TNode) node.getNextSibling()) {
buf.append(node.getText());
@@ -304,7 +304,7 @@ public TNode deepCopyWithRightSiblings() {
/** return a short string representation of the node */
public String toString() {
- StringBuffer str = new StringBuffer( getNameForType(getType()) +
+ StringBuilder str = new StringBuilder( getNameForType(getType()) +
"[" + getText() + ", " + "]");
if(this.getLineNum() != 0)
@@ -111,7 +111,7 @@ public String toString() {
}
public String toString(String variableName) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append(elementType.getName());
if (variableName != null) {
buf.append(" ");
@@ -206,7 +206,7 @@ public String getStructString() {
try {
visiting = true;
String kind = (isStruct() ? "struct {" : "union {");
- StringBuffer res = new StringBuffer();
+ StringBuilder res = new StringBuilder();
res.append(kind);
int n = getNumFields();
for (int i = 0; i < n; i++) {
@@ -134,7 +134,7 @@ public String toString(String functionName, boolean emitNativeTag) {
}
String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) {
- StringBuffer res = new StringBuffer();
+ StringBuilder res = new StringBuilder();
res.append(getReturnType());
res.append(" ");
if (isPointer) {
@@ -43,7 +43,6 @@
import com.jogamp.gluegen.MethodBinding;
import com.jogamp.gluegen.JavaType;
import java.io.*;
-import com.jogamp.gluegen.*;
import com.jogamp.gluegen.cgram.types.*;
public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
@@ -203,7 +202,7 @@ protected void emitBodyCallCFunction(PrintWriter writer) {
@Override
protected String jniMangle(MethodBinding binding) {
- StringBuffer buf = new StringBuffer(super.jniMangle(binding));
+ StringBuilder buf = new StringBuilder(super.jniMangle(binding));
if (callThroughProcAddress) {
jniMangle(Long.TYPE, buf, false); // to account for the additional _addr_ parameter
}
@@ -197,7 +197,7 @@ public static final Object createInstance(Constructor<?> cstr, Object ... cstrAr
protected static final Class<?>[] zeroTypes = new Class[0];
protected static final String asString(Class<?>[] argTypes) {
- StringBuffer args = new StringBuffer();
+ StringBuilder args = new StringBuilder();
boolean coma = false;
if(null != argTypes) {
for (int i = 0; i < argTypes.length; i++) {
@@ -116,7 +116,7 @@ public final void removeOwner(Thread t) throws IllegalArgumentException {
}
String addOwnerToString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for(int i=0; i<threadNum; i++) {
if(i>0) {
sb.append(", ");

0 comments on commit 900b2a7

Please sign in to comment.