Skip to content

Commit d0e696c

Browse files
committed
Merge pull request processing#2863 from federicobond/migrate-unsynchronized
Migrate to unsynchronized data structures
2 parents b785e1d + a6913cf commit d0e696c

30 files changed

Lines changed: 179 additions & 196 deletions

app/src/antlr/ExtendedCommonASTWithHiddenTokens.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void initialize(AST ast) {
3737
public String getHiddenAfterString() {
3838

3939
CommonHiddenStreamToken t;
40-
StringBuffer hiddenAfterString = new StringBuffer(100);
40+
StringBuilder hiddenAfterString = new StringBuilder(100);
4141

4242
for ( t = hiddenAfter ; t != null ; t = t.getHiddenAfter() ) {
4343
hiddenAfterString.append(t.getText());
@@ -66,7 +66,7 @@ public String getHiddenBeforeString() {
6666

6767
// dump that list
6868

69-
StringBuffer hiddenBeforeString = new StringBuffer(100);
69+
StringBuilder hiddenBeforeString = new StringBuilder(100);
7070

7171
for ( CommonHiddenStreamToken t = child; t != null ;
7272
t = t.getHiddenAfter() ) {
@@ -76,31 +76,29 @@ public String getHiddenBeforeString() {
7676
return hiddenBeforeString.toString();
7777
}
7878

79-
public void xmlSerializeNode(Writer out)
80-
throws IOException {
81-
StringBuffer buf = new StringBuffer(100);
82-
buf.append("<");
83-
buf.append(getClass().getName() + " ");
84-
85-
buf.append("hiddenBeforeString=\"" +
86-
encode(getHiddenBeforeString()) +
87-
"\" text=\"" + encode(getText()) + "\" type=\"" +
88-
getType() + "\" hiddenAfterString=\"" +
89-
encode(getHiddenAfterString()) + "\"/>");
90-
out.write(buf.toString());
79+
public void xmlSerializeNode(Writer out) throws IOException {
80+
StringBuilder sb = new StringBuilder(100);
81+
sb.append("<");
82+
sb.append(getClass().getName() + " ");
83+
84+
sb.append("hiddenBeforeString=\"" +
85+
encode(getHiddenBeforeString()) +
86+
"\" text=\"" + encode(getText()) + "\" type=\"" +
87+
getType() + "\" hiddenAfterString=\"" +
88+
encode(getHiddenAfterString()) + "\"/>");
89+
out.write(sb.toString());
9190
}
9291

93-
public void xmlSerializeRootOpen(Writer out)
94-
throws IOException {
95-
StringBuffer buf = new StringBuffer(100);
96-
buf.append("<");
97-
buf.append(getClass().getName() + " ");
98-
buf.append("hiddenBeforeString=\"" +
99-
encode(getHiddenBeforeString()) +
100-
"\" text=\"" + encode(getText()) + "\" type=\"" +
101-
getType() + "\" hiddenAfterString=\"" +
102-
encode(getHiddenAfterString()) + "\">\n");
103-
out.write(buf.toString());
92+
public void xmlSerializeRootOpen(Writer out) throws IOException {
93+
StringBuilder sb = new StringBuilder(100);
94+
sb.append("<");
95+
sb.append(getClass().getName() + " ");
96+
sb.append("hiddenBeforeString=\"" +
97+
encode(getHiddenBeforeString()) +
98+
"\" text=\"" + encode(getText()) + "\" type=\"" +
99+
getType() + "\" hiddenAfterString=\"" +
100+
encode(getHiddenAfterString()) + "\">\n");
101+
out.write(sb.toString());
104102
}
105103

106104
public void xmlSerializeRootClose(Writer out)

app/src/processing/app/Base.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,17 +2780,12 @@ public boolean accept(File dir, String name) {
27802780
static public String contentsToClassPath(File folder) {
27812781
if (folder == null) return "";
27822782

2783-
StringBuffer abuffer = new StringBuffer();
2783+
StringBuilder sb = new StringBuilder();
27842784
String sep = System.getProperty("path.separator");
27852785

27862786
try {
27872787
String path = folder.getCanonicalPath();
27882788

2789-
// disabled as of 0136
2790-
// add the folder itself in case any unzipped files
2791-
// abuffer.append(sep);
2792-
// abuffer.append(path);
2793-
//
27942789
// When getting the name of this folder, make sure it has a slash
27952790
// after it, so that the names of sub-items can be added.
27962791
if (!path.endsWith(File.separator)) {
@@ -2805,17 +2800,15 @@ static public String contentsToClassPath(File folder) {
28052800

28062801
if (list[i].toLowerCase().endsWith(".jar") ||
28072802
list[i].toLowerCase().endsWith(".zip")) {
2808-
abuffer.append(sep);
2809-
abuffer.append(path);
2810-
abuffer.append(list[i]);
2803+
sb.append(sep);
2804+
sb.append(path);
2805+
sb.append(list[i]);
28112806
}
28122807
}
28132808
} catch (IOException e) {
28142809
e.printStackTrace(); // this would be odd
28152810
}
2816-
//System.out.println("included path is " + abuffer.toString());
2817-
//packageListFromClassPath(abuffer.toString()); // WHY?
2818-
return abuffer.toString();
2811+
return sb.toString();
28192812
}
28202813

28212814

@@ -2828,7 +2821,7 @@ static public String contentsToClassPath(File folder) {
28282821
* @return array of possible package names
28292822
*/
28302823
static public String[] packageListFromClassPath(String path) {
2831-
Hashtable table = new Hashtable();
2824+
Map<String, Object> map = new HashMap<String, Object>();
28322825
String pieces[] =
28332826
PApplet.split(path, File.pathSeparatorChar);
28342827

@@ -2839,32 +2832,32 @@ static public String[] packageListFromClassPath(String path) {
28392832
if (pieces[i].toLowerCase().endsWith(".jar") ||
28402833
pieces[i].toLowerCase().endsWith(".zip")) {
28412834
//System.out.println("checking " + pieces[i]);
2842-
packageListFromZip(pieces[i], table);
2835+
packageListFromZip(pieces[i], map);
28432836

28442837
} else { // it's another type of file or directory
28452838
File dir = new File(pieces[i]);
28462839
if (dir.exists() && dir.isDirectory()) {
2847-
packageListFromFolder(dir, null, table);
2840+
packageListFromFolder(dir, null, map);
28482841
//importCount = magicImportsRecursive(dir, null,
2849-
// table);
2842+
// map);
28502843
//imports, importCount);
28512844
}
28522845
}
28532846
}
2854-
int tableCount = table.size();
2855-
String output[] = new String[tableCount];
2847+
int mapCount = map.size();
2848+
String output[] = new String[mapCount];
28562849
int index = 0;
2857-
Enumeration e = table.keys();
2858-
while (e.hasMoreElements()) {
2859-
output[index++] = ((String) e.nextElement()).replace('/', '.');
2850+
Set<String> set = map.keySet();
2851+
for (String s : set) {
2852+
output[index++] = s.replace('/', '.');
28602853
}
28612854
//System.arraycopy(imports, 0, output, 0, importCount);
28622855
//PApplet.printarr(output);
28632856
return output;
28642857
}
28652858

28662859

2867-
static private void packageListFromZip(String filename, Hashtable table) {
2860+
static private void packageListFromZip(String filename, Map<String, Object> map) {
28682861
try {
28692862
ZipFile file = new ZipFile(filename);
28702863
Enumeration entries = file.entries();
@@ -2879,8 +2872,8 @@ static private void packageListFromZip(String filename, Hashtable table) {
28792872
if (slash == -1) continue;
28802873

28812874
String pname = name.substring(0, slash);
2882-
if (table.get(pname) == null) {
2883-
table.put(pname, new Object());
2875+
if (map.get(pname) == null) {
2876+
map.put(pname, new Object());
28842877
}
28852878
}
28862879
}
@@ -2900,7 +2893,7 @@ static private void packageListFromZip(String filename, Hashtable table) {
29002893
* walk down into that folder and continue.
29012894
*/
29022895
static private void packageListFromFolder(File dir, String sofar,
2903-
Hashtable table) {
2896+
Map<String, Object> map) {
29042897
//String imports[],
29052898
//int importCount) {
29062899
//System.err.println("checking dir '" + dir + "'");
@@ -2914,15 +2907,15 @@ static private void packageListFromFolder(File dir, String sofar,
29142907
if (sub.isDirectory()) {
29152908
String nowfar =
29162909
(sofar == null) ? files[i] : (sofar + "." + files[i]);
2917-
packageListFromFolder(sub, nowfar, table);
2910+
packageListFromFolder(sub, nowfar, map);
29182911
//System.out.println(nowfar);
29192912
//imports[importCount++] = nowfar;
29202913
//importCount = magicImportsRecursive(sub, nowfar,
29212914
// imports, importCount);
29222915
} else if (!foundClass) { // if no classes found in this folder yet
29232916
if (files[i].endsWith(".class")) {
29242917
//System.out.println("unique class: " + files[i] + " for " + sofar);
2925-
table.put(sofar, new Object());
2918+
map.put(sofar, new Object());
29262919
foundClass = true;
29272920
}
29282921
}

app/src/processing/app/Sketch.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,24 +1570,24 @@ static final boolean asciiLetter(char c) {
15701570
*/
15711571
static public String sanitizeName(String origName) {
15721572
char orig[] = origName.toCharArray();
1573-
StringBuffer buffer = new StringBuffer();
1573+
StringBuilder sb = new StringBuilder();
15741574

15751575
// Can't lead with a digit (or anything besides a letter), so prefix with
15761576
// "sketch_". In 1.x this prefixed with an underscore, but those get shaved
15771577
// off later, since you can't start a sketch name with underscore anymore.
15781578
if (!asciiLetter(orig[0])) {
1579-
buffer.append("sketch_");
1579+
sb.append("sketch_");
15801580
}
15811581
// for (int i = 0; i < orig.length; i++) {
15821582
for (char c : orig) {
15831583
if (asciiLetter(c) || (c >= '0' && c <= '9')) {
1584-
buffer.append(c);
1584+
sb.append(c);
15851585

15861586
} else {
15871587
// Tempting to only add if prev char is not underscore, but that
15881588
// might be more confusing if lots of chars are converted and the
15891589
// result is a very short string thats nothing like the original.
1590-
buffer.append('_');
1590+
sb.append('_');
15911591
}
15921592
}
15931593
// Let's not be ridiculous about the length of filenames.
@@ -1596,22 +1596,22 @@ static public String sanitizeName(String origName) {
15961596
// Limiting to that for sketches would mean setting the
15971597
// upper-bound on the character limit here to 25 characters
15981598
// (to handle the base name + ".class")
1599-
if (buffer.length() > 63) {
1600-
buffer.setLength(63);
1599+
if (sb.length() > 63) {
1600+
sb.setLength(63);
16011601
}
16021602
// Remove underscores from the beginning, these seem to be a reserved
16031603
// thing on Android, plus it sometimes causes trouble elsewhere.
16041604
int underscore = 0;
1605-
while (underscore < buffer.length() && buffer.charAt(underscore) == '_') {
1605+
while (underscore < sb.length() && sb.charAt(underscore) == '_') {
16061606
underscore++;
16071607
}
1608-
if (underscore == buffer.length()) {
1608+
if (underscore == sb.length()) {
16091609
return "bad_sketch_name_please_fix";
16101610

16111611
} else if (underscore != 0) {
1612-
return buffer.substring(underscore);
1612+
return sb.substring(underscore);
16131613
}
1614-
return buffer.toString();
1614+
return sb.toString();
16151615
}
16161616

16171617

app/src/processing/app/WebServer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ protected static void log(String s) {
109109
//public static void main(String[] a) throws Exception {
110110
static public int launch(String zipPath) throws IOException {
111111
final ZipFile zip = new ZipFile(zipPath);
112-
final HashMap<String, ZipEntry> entries = new HashMap();
112+
final Map<String, ZipEntry> entries = new HashMap<String, ZipEntry>();
113113
Enumeration en = zip.entries();
114114
while (en.hasMoreElements()) {
115115
ZipEntry entry = (ZipEntry) en.nextElement();
116116
entries.put(entry.getName(), entry);
117117
}
118-
118+
119119
// if (a.length > 0) {
120120
// port = Integer.parseInt(a[0]);
121121
// }
@@ -164,9 +164,9 @@ public void run() {
164164

165165

166166
class WebServerWorker /*extends WebServer*/ implements HttpConstants, Runnable {
167-
ZipFile zip;
168-
HashMap<String, ZipEntry> entries;
169-
167+
private final ZipFile zip;
168+
private final Map<String, ZipEntry> entries;
169+
170170
final static int BUF_SIZE = 2048;
171171

172172
static final byte[] EOL = { (byte)'\r', (byte)'\n' };
@@ -176,10 +176,10 @@ class WebServerWorker /*extends WebServer*/ implements HttpConstants, Runnable {
176176
/* Socket to client we're handling */
177177
private Socket s;
178178

179-
WebServerWorker(ZipFile zip, HashMap entries) {
179+
WebServerWorker(ZipFile zip, Map<String, ZipEntry> entries) {
180180
this.entries = entries;
181181
this.zip = zip;
182-
182+
183183
buf = new byte[BUF_SIZE];
184184
s = null;
185185
}
@@ -468,7 +468,7 @@ void sendFile(InputStream is, PrintStream ps) throws IOException {
468468
}
469469

470470
/* mapping of file extensions to content-types */
471-
static java.util.Hashtable map = new java.util.Hashtable();
471+
static Map<String, String> map = new HashMap<String, String>();
472472

473473
static {
474474
fillMap();

app/src/processing/app/exec/ProcessHelper.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ public ProcessHelper(File dir, final String... cmd) {
5050

5151
@Override
5252
public String toString() {
53-
/*
54-
final StringBuffer buffer = new StringBuffer();
55-
for (int i = 0; i < cmd.length; i++) {
56-
if (i != 0) {
57-
buffer.append(' ');
58-
}
59-
buffer.append(cmd[i]);
60-
}
61-
return buffer.toString();
62-
*/
63-
// return exe + " " + PApplet.join(args, " ");
6453
return PApplet.join(cmd, " ");
6554
}
6655

@@ -143,4 +132,4 @@ static public boolean ffs(final String... cmd) {
143132
}
144133
return false;
145134
}
146-
}
135+
}

0 commit comments

Comments
 (0)