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;

View File

@@ -24,7 +24,6 @@ import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.SWFSourceInfo;
import com.jpexs.decompiler.flash.SearchMode;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.RenameType;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
@@ -69,7 +68,6 @@ import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings;
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.importers.BinaryDataImporter;
import com.jpexs.decompiler.flash.importers.ImageImporter;
import com.jpexs.decompiler.flash.importers.SwfXmlImporter;
@@ -1438,14 +1436,14 @@ public class CommandLineArgumentParser {
replaceAS2PCode(repText, src);
}
} else {
List<MyEntry<ClassPath, ScriptPack>> packs = swf.getAS3Packs();
for (MyEntry<ClassPath, ScriptPack> entry : packs) {
if (entry.getKey().toString().equals(objectToReplace)) {
List<ScriptPack> packs = swf.getAS3Packs();
for (ScriptPack entry : packs) {
if (entry.getClassPath().toString().equals(objectToReplace)) {
found = true;
// replace AS3
String repFile = args.pop();
String repText = Helper.readTextFile(repFile);
ScriptPack pack = entry.getValue();
ScriptPack pack = entry;
if (Path.getExtension(repFile).equals(".as")) {
replaceAS3(repText, pack);
} else {
@@ -1627,9 +1625,9 @@ public class CommandLineArgumentParser {
try {
try (FileInputStream is = new FileInputStream(file)) {
SWF swf = new SWF(is, Configuration.parallelSpeedUp.get());
List<MyEntry<ClassPath, ScriptPack>> packs = swf.getAS3Packs();
for (MyEntry<ClassPath, ScriptPack> entry : packs) {
System.out.println(entry.getKey().toString() + " " + entry.getValue().scriptIndex);
List<ScriptPack> packs = swf.getAS3Packs();
for (ScriptPack entry : packs) {
System.out.println(entry.getClassPath().toString() + " " + entry.scriptIndex);
}
}
} catch (IOException | InterruptedException e) {

View File

@@ -867,22 +867,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public void doFilter() {
List<TreeItem> nodes = getASTreeNodes(tagTree);
boolean updateNeeded = false;
for (TreeItem n : nodes) {
if (n instanceof ClassesListTreeModel) {
((ClassesListTreeModel) n).setFilter(filterField.getText());
updateNeeded = true;
TagTreeModel tm = tagTree.getModel();
tm.updateNode(n);
View.expandTreeNodes(tagTree, tm.getTreePath(n), true);
}
}
if (updateNeeded) {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
tagTree.updateUI();
}
});
}
}
@Override

View File

@@ -58,7 +58,6 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.StringTableModel;
import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.helpers.Freed;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import com.jpexs.decompiler.graph.CompilationException;
@@ -177,16 +176,15 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
final List<ABCPanelSearchResult> found = new ArrayList<>();
if (scriptsNode instanceof ClassesListTreeModel) {
ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode;
List<MyEntry<ClassPath, ScriptPack>> allpacks = clModel.getList();
List<ScriptPack> allpacks = clModel.getList();
final Pattern pat = regexp
? Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0)
: Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
int pos = 0;
for (final MyEntry<ClassPath, ScriptPack> item : allpacks) {
for (final ScriptPack pack : allpacks) {
pos++;
String workText = AppStrings.translate("work.searching");
String decAdd = "";
final ScriptPack pack = item.getValue();
if (!SWF.isCached(pack)) {
decAdd = ", " + AppStrings.translate("work.decompiling");
}
@@ -199,14 +197,13 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
if (pat.matcher(SWF.getCached(pack).text).find()) {
ABCPanelSearchResult searchResult = new ABCPanelSearchResult();
searchResult.scriptPack = pack;
searchResult.classPath = item.getKey();
found.add(searchResult);
}
return null;
}
};
worker.execute();
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + allpacks.size() + ") " + item.getKey().toString() + "... ", worker);
Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ", worker);
worker.get();
} catch (InterruptedException ex) {
break;
@@ -686,12 +683,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
if (scriptsNode instanceof ClassesListTreeModel) {
ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode;
ScriptPack pack = null;
for (MyEntry<ClassPath, ScriptPack> item : clModel.getList()) {
ClassPath classPath = item.getKey();
for (ScriptPack item : clModel.getList()) {
ClassPath classPath = item.getClassPath();
// first check the className to avoid calling unnecessary toString
if (name.endsWith(classPath.className) && classPath.toString().equals(name)) {
pack = item.getValue();
pack = item;
break;
}
}
@@ -807,9 +804,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
try {
String oldSp = null;
List<MyEntry<ClassPath, ScriptPack>> packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex);
List<ScriptPack> packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex);
if (!packs.isEmpty()) {
oldSp = packs.get(0).getKey().toString();
oldSp = packs.get(0).getClassPath().toString();
}
String as = decompiledTextArea.getText();

View File

@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
/**
@@ -27,10 +26,8 @@ public class ABCPanelSearchResult {
public ScriptPack scriptPack;
public ClassPath classPath;
@Override
public String toString() {
return classPath.toString();
return scriptPack.getClassPath().toString();
}
}

View File

@@ -17,12 +17,10 @@
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.SWF;
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.TraitClass;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.timeline.AS3Package;
import com.jpexs.decompiler.flash.treeitems.AS3ClassTreeItem;
import java.util.ArrayList;
@@ -37,13 +35,13 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
private SWF swf;
private List<MyEntry<ClassPath, ScriptPack>> list;
private List<ScriptPack> list;
private AS3Package root;
private final List<TreeModelListener> listeners = new ArrayList<>();
public List<MyEntry<ClassPath, ScriptPack>> getList() {
public List<ScriptPack> getList() {
return list;
}
@@ -73,19 +71,18 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
}
public final void setFilter(String filter) {
root.scripts.clear();
root.subPackages.clear();
root.clear();
filter = (filter == null || filter.isEmpty()) ? null : filter.toLowerCase();
for (MyEntry<ClassPath, ScriptPack> item : list) {
for (ScriptPack item : list) {
if (filter != null) {
if (!item.getKey().toString().toLowerCase().contains(filter)) {
if (!item.getClassPath().toString().toLowerCase().contains(filter)) {
continue;
}
}
AS3Package pkg = ensurePackage(item.getKey().packageStr);
pkg.scripts.put(item.getKey().className, item.getValue());
AS3Package pkg = ensurePackage(item.getClassPath().packageStr);
pkg.addScriptPack(item);
}
}
@@ -94,10 +91,10 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
AS3Package parent = root;
while (st.hasMoreTokens()) {
String pathElement = st.nextToken();
AS3Package pkg = parent.subPackages.get(pathElement);
AS3Package pkg = parent.getSubPackage(pathElement);
if (pkg == null) {
pkg = new AS3Package(pathElement, swf);
parent.subPackages.put(pathElement, pkg);
parent.addSubPackage(pkg);
}
parent = pkg;
@@ -111,14 +108,14 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
}
private ScriptPack getElementByClassIndexRecursive(AS3Package item, int classIndex) {
for (AS3Package pkg : item.subPackages.values()) {
for (AS3Package pkg : item.getSubPackages()) {
ScriptPack result = getElementByClassIndexRecursive(pkg, classIndex);
if (result != null) {
return result;
}
}
for (ScriptPack sc : item.scripts.values()) {
for (ScriptPack sc : item.getScriptPacks()) {
for (Trait t : sc.abc.script_info.get(sc.scriptIndex).traits.traits) {
if (t instanceof TraitClass) {
if (((TraitClass) t).class_info == classIndex) {
@@ -140,7 +137,7 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
AS3Package pkg = (AS3Package) parent;
return pkg.getAllChildren();
}
@Override
public AS3ClassTreeItem getChild(Object parent, int index) {
AS3Package pkg = (AS3Package) parent;

View File

@@ -18,14 +18,12 @@ package com.jpexs.decompiler.flash.gui.debugger;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.DebugLogDialog;
import com.jpexs.decompiler.flash.gui.Main;
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.helpers.Helper;
@@ -49,9 +47,9 @@ public class DebuggerTools {
private static ScriptPack getDebuggerScriptPack(SWF swf) {
for (ABCContainerTag ac : swf.getAbcList()) {
ABC a = ac.getABC();
for (MyEntry<ClassPath, ScriptPack> m : a.getScriptPacks()) {
if (isDebuggerClass(m.getKey().packageStr, null)) {
return m.getValue();
for (ScriptPack m : a.getScriptPacks()) {
if (isDebuggerClass(m.getClassPath().packageStr, null)) {
return m;
}
}
}