performance fixes

This commit is contained in:
honfika@gmail.com
2015-03-19 21:22:39 +01:00
parent 9095d75d5e
commit 2ada8667bb
10 changed files with 122 additions and 108 deletions

View File

@@ -1144,11 +1144,11 @@ public final class SWF implements SWFContainerItem, Timelined {
return exported;
}
private List<MyEntry<ClassPath, ScriptPack>> uniqueAS3Packs(List<MyEntry<ClassPath, ScriptPack>> packs) {
List<MyEntry<ClassPath, ScriptPack>> ret = new ArrayList<>();
private List<ScriptPack> uniqueAS3Packs(List<ScriptPack> packs) {
List<ScriptPack> ret = new ArrayList<>();
Set<ClassPath> classPaths = new HashSet<>();
for (MyEntry<ClassPath, ScriptPack> item : packs) {
ClassPath key = item.getKey();
for (ScriptPack item : packs) {
ClassPath key = item.getClassPath();
if (classPaths.contains(key)) {
logger.log(Level.SEVERE, "Duplicate pack path found (" + key + ")!");
} else {
@@ -1159,8 +1159,8 @@ public final class SWF implements SWFContainerItem, Timelined {
return ret;
}
public List<MyEntry<ClassPath, ScriptPack>> getAS3Packs() {
List<MyEntry<ClassPath, ScriptPack>> packs = new ArrayList<>();
public List<ScriptPack> getAS3Packs() {
List<ScriptPack> packs = new ArrayList<>();
for (ABCContainerTag abcTag : getAbcList()) {
packs.addAll(abcTag.getABC().getScriptPacks());
}
@@ -1256,15 +1256,15 @@ public final class SWF implements SWFContainerItem, Timelined {
final AtomicInteger cnt = new AtomicInteger(1);
final List<File> ret = new ArrayList<>();
final List<MyEntry<ClassPath, ScriptPack>> packs = getAS3Packs();
final List<ScriptPack> packs = getAS3Packs();
if (!parallel || packs.size() < 2) {
try {
CancellableWorker.call(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (MyEntry<ClassPath, ScriptPack> item : packs) {
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, exportMode, parallel, evl);
for (ScriptPack item : packs) {
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl);
ret.add(task.call());
}
return null;
@@ -1278,8 +1278,8 @@ public final class SWF implements SWFContainerItem, Timelined {
} else {
ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount());
List<Future<File>> futureResults = new ArrayList<>();
for (MyEntry<ClassPath, ScriptPack> item : packs) {
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, exportMode, parallel, evl));
for (ScriptPack item : packs) {
Future<File> future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl));
futureResults.add(future);
}

View File

@@ -55,7 +55,6 @@ import com.jpexs.decompiler.flash.abc.usages.MethodReturnTypeMultinameUsage;
import com.jpexs.decompiler.flash.abc.usages.MultinameUsage;
import com.jpexs.decompiler.flash.abc.usages.TypeNameMultinameUsage;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.types.annotations.Internal;
@@ -867,8 +866,8 @@ public class ABC {
}
}
public List<MyEntry<ClassPath, ScriptPack>> getScriptPacks() {
List<MyEntry<ClassPath, ScriptPack>> ret = new ArrayList<>();
public List<ScriptPack> getScriptPacks() {
List<ScriptPack> ret = new ArrayList<>();
for (int i = 0; i < script_info.size(); i++) {
ret.addAll(script_info.get(i).getPacks(this, i));
}
@@ -1046,22 +1045,23 @@ public class ABC {
public List<ScriptPack> findScriptPacksByPath(String name) {
List<ScriptPack> ret = new ArrayList<>();
List<MyEntry<ClassPath, ScriptPack>> allPacks = getScriptPacks();
List<ScriptPack> allPacks = getScriptPacks();
if (name.endsWith(".**") || name.equals("**") || name.endsWith(".++") || name.equals("++")) {
name = name.substring(0, name.length() - 2);
for (MyEntry<ClassPath, ScriptPack> en : allPacks) {
if (en.getKey().toString().startsWith(name)) {
ret.add(en.getValue());
for (ScriptPack en : allPacks) {
if (en.getClassPath().toString().startsWith(name)) {
ret.add(en);
}
}
} else if (name.endsWith(".*") || name.equals("*") || name.endsWith(".+") || name.equals("+")) {
name = name.substring(0, name.length() - 1);
for (MyEntry<ClassPath, ScriptPack> en : allPacks) {
if (en.getKey().toString().startsWith(name)) {
String rem = name.isEmpty() ? en.getKey().toString() : en.getKey().toString().substring(name.length());
for (ScriptPack en : allPacks) {
String classPathStr = en.getClassPath().toString();
if (classPathStr.startsWith(name)) {
String rem = name.isEmpty() ? classPathStr : classPathStr.substring(name.length());
if (!rem.contains(".")) {
ret.add(en.getValue());
ret.add(en);
}
}
}
@@ -1076,10 +1076,10 @@ public class ABC {
}
public ScriptPack findScriptPackByPath(String name) {
List<MyEntry<ClassPath, ScriptPack>> packs = getScriptPacks();
for (MyEntry<ClassPath, ScriptPack> en : packs) {
if (en.getKey().toString().equals(name)) {
return en.getValue();
List<ScriptPack> packs = getScriptPacks();
for (ScriptPack en : packs) {
if (en.getClassPath().toString().equals(name)) {
return en;
}
}
return null;

View File

@@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import java.util.ArrayList;
import java.util.List;
@@ -36,13 +35,13 @@ public class ScriptInfo {
public ScriptInfo() {
traits = new Traits();
}
public ScriptInfo(Traits traits) {
this.traits = traits;
}
public List<MyEntry<ClassPath, ScriptPack>> getPacks(ABC abc, int scriptIndex) {
List<MyEntry<ClassPath, ScriptPack>> ret = new ArrayList<>();
public List<ScriptPack> getPacks(ABC abc, int scriptIndex) {
List<ScriptPack> ret = new ArrayList<>();
List<Integer> otherTraits = new ArrayList<>();
for (int j = 0; j < traits.traits.size(); j++) {
@@ -70,7 +69,7 @@ public class ScriptInfo {
}
otherTraits = new ArrayList<>();
ClassPath cp = new ClassPath(packageName, objectName);
ret.add(new MyEntry<>(cp, new ScriptPack(cp, abc, scriptIndex, traitIndices)));
ret.add(new ScriptPack(cp, abc, scriptIndex, traitIndices));
}
}
return ret;

View File

@@ -34,9 +34,13 @@ public class AS3Package extends AS3ClassTreeItem {
public String packageName;
public Map<String, AS3Package> subPackages = new TreeMap<>();
private final Map<String, AS3Package> subPackages = new TreeMap<>();
public Map<String, ScriptPack> scripts = new TreeMap<>();
private final Map<String, ScriptPack> scripts = new TreeMap<>();
private List<AS3Package> sortedPackages;
private List<ScriptPack> sortedScripts;
public AS3Package(String packageName, SWF swf) {
super(packageName, null);
@@ -49,35 +53,60 @@ public class AS3Package extends AS3ClassTreeItem {
return swf;
}
public List<AS3Package> getSubPackages() {
if (sortedPackages == null) {
List<AS3Package> list = new ArrayList<>();
for (AS3Package subPackage : subPackages.values()) {
list.add(subPackage);
}
sortedPackages = list;
}
return sortedPackages;
}
public List<ScriptPack> getScriptPacks() {
if (sortedScripts == null) {
List<ScriptPack> list = new ArrayList<>();
for (ScriptPack script : scripts.values()) {
list.add(script);
}
sortedScripts = list;
}
return sortedScripts;
}
public void addScriptPack(ScriptPack script) {
scripts.put(script.getClassPath().className, script);
sortedScripts = null;
}
public void addSubPackage(AS3Package subPackage) {
subPackages.put(subPackage.getName(), subPackage);
sortedPackages = null;
}
public AS3Package getSubPackage(String packageName) {
return subPackages.get(packageName);
}
public List<AS3ClassTreeItem> getAllChildren() {
List<AS3ClassTreeItem> result = new ArrayList<>(getChildCount());
result.addAll(subPackages.values());
result.addAll(scripts.values());
return result;
}
public AS3ClassTreeItem getChild(int index) {
if (index < subPackages.size()) {
for (AS3Package subPackage : subPackages.values()) {
if (index == 0) {
return subPackage;
}
index--;
}
return getSubPackages().get(index);
}
index -= subPackages.size();
for (ScriptPack pack : scripts.values()) {
if (index == 0) {
return pack;
}
index--;
}
return null;
return getScriptPacks().get(index);
}
public int getChildCount() {
@@ -107,6 +136,13 @@ public class AS3Package extends AS3ClassTreeItem {
return res;
}
public void clear() {
subPackages.clear();
scripts.clear();
sortedPackages = null;
sortedScripts = null;
}
@Override
public String toString() {
return packageName;