copy-paste performance improvement

This commit is contained in:
bancika
2012-08-15 21:18:31 +00:00
parent 5a4eeb2de2
commit 4f88bb988a
@@ -3,6 +3,7 @@ package org.diylc.presenter;
import java.awt.Point; import java.awt.Point;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -172,15 +173,19 @@ public class InstantiationManager {
public String createUniqueName(ComponentType componentType, Project currentProject) { public String createUniqueName(ComponentType componentType, Project currentProject) {
int i = 0; int i = 0;
boolean exists = true; boolean exists = true;
List<IDIYComponent<?>> components = currentProject.getComponents();
String[] takenNames = new String[components.size()];
for (int j = 0; j < currentProject.getComponents().size(); j++) {
takenNames[j] = components.get(i).getName();
}
Arrays.sort(takenNames);
while (exists) { while (exists) {
i++; i++;
String name = componentType.getNamePrefix() + i; String name = componentType.getNamePrefix() + i;
exists = false; exists = false;
for (IDIYComponent<?> c : currentProject.getComponents()) { if (Arrays.binarySearch(takenNames, name) >= 0) {
if (c.getName().equals(name)) { exists = true;
exists = true; break;
break;
}
} }
} }
return componentType.getNamePrefix() + i; return componentType.getNamePrefix() + i;