diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java
index 4e1858ad2..256b3790d 100644
--- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java
+++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java
@@ -32,6 +32,7 @@ import java.awt.event.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@@ -43,7 +44,6 @@ import javax.swing.table.*;
import javax.swing.tree.TreePath;
import jsyntaxpane.DefaultSyntaxKit;
import jsyntaxpane.actions.DocumentSearchData;
-import jsyntaxpane.actions.gui.QuickFindDialog;
public class ABCPanel extends JPanel implements ItemListener, ActionListener {
@@ -94,6 +94,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
found.add(p);
}
}
+
+ System.gc();
+
//found = decompiledTextArea.searchCache(txt, ignoreCase, regexp);
if (found.isEmpty()) {
searchPanel.setVisible(false);
@@ -449,17 +452,17 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
Main.mainFrame.tagTree.setSelectionPath(tp);
Main.mainFrame.tagTree.scrollPathToVisible(tp);
decompiledTextArea.setCaretPosition(0);
- try {
- Thread.sleep(100);
- } catch (InterruptedException ex) {
- Logger.getLogger(ABCPanel.class.getName()).log(Level.SEVERE, null, ex);
- }
- DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledTextArea);
- dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase);
- QuickFindDialog quickFindDlg = new QuickFindDialog(decompiledTextArea, dsd);
- quickFindDlg.setRegularExpression(searchRegexp);
- quickFindDlg.setIgnoreCase(searchIgnoreCase);
- quickFindDlg.showFor(decompiledTextArea);
+ java.util.Timer t = new java.util.Timer();
+ t.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledTextArea);
+ dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase);
+ dsd.showQuickFindDialogEx(decompiledTextArea, searchIgnoreCase, searchRegexp);
+ }
+ }, 1000);
+
+
}
@Override
diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/CachedDecompilation.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/CachedDecompilation.java
new file mode 100644
index 000000000..64019fb3d
--- /dev/null
+++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/CachedDecompilation.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 JPEXS
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.jpexs.decompiler.flash.abc.gui;
+
+import com.jpexs.decompiler.flash.helpers.Highlighting;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ *
+ * @author JPEXS
+ */
+public class CachedDecompilation implements Serializable {
+
+ public String text;
+ public String hilightedText;
+
+ public List getHighlights() {
+ return Highlighting.getInstrHighlights(hilightedText);
+ }
+
+ public List getTraitHighlights() {
+ return Highlighting.getTraitHighlights(hilightedText);
+ }
+
+ public List getMethodHighlights() {
+ return Highlighting.getMethodHighlights(hilightedText);
+ }
+
+ public List getClassHighlights() {
+ return Highlighting.getClassHighlights(hilightedText);
+ }
+
+ public CachedDecompilation(String hilightedText) {
+ this.hilightedText = hilightedText;
+ this.text = Highlighting.stripHilights(hilightedText);
+ }
+}
diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java
index 0b5b3ce16..714263f46 100644
--- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java
+++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DecompiledEditorPane.java
@@ -21,17 +21,13 @@ import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
+import com.jpexs.decompiler.flash.helpers.Cache;
import com.jpexs.decompiler.flash.helpers.Highlighting;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.regex.Pattern;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
@@ -50,6 +46,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
private ABCPanel abcPanel;
private int classIndex = -1;
private boolean isStatic = false;
+ private Cache cache = new Cache();
public ScriptPack getScriptLeaf() {
return script;
@@ -216,61 +213,16 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
}
}
- private class CachedDecompilation {
-
- public String text;
- public String hilightedText;
-
- public List getHighlights() {
- return Highlighting.getInstrHighlights(hilightedText);
- }
-
- public List getTraitHighlights() {
- return Highlighting.getTraitHighlights(hilightedText);
- }
-
- public List getMethodHighlights() {
- return Highlighting.getMethodHighlights(hilightedText);
- }
-
- public List getClassHighlights() {
- return Highlighting.getClassHighlights(hilightedText);
- }
-
- public CachedDecompilation(String hilightedText) {
- this.hilightedText = hilightedText;
- this.text = Highlighting.stripHilights(hilightedText);
- }
- }
- private List cacheKeys = new LinkedList();
- private List cacheValues = new LinkedList();
-
private void uncache(ScriptPack pack) {
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == pack) {
- cacheValues.remove(i);
- cacheKeys.remove(i);
- break;
- }
- }
+ cache.remove(pack);
}
private CachedDecompilation getCached(ScriptPack pack) {
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == pack) {
- return cacheValues.get(i);
- }
- }
- return null;
+ return (CachedDecompilation) cache.get(pack);
}
public String getCachedText(ScriptPack pack) {
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == pack) {
- return cacheValues.get(i).text;
- }
- }
- return null;
+ return getCached(pack).text;
}
public void gotoLastTrait() {
@@ -326,8 +278,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
private List abcList;
public void clearScriptCache() {
- cacheKeys.clear();
- cacheValues.clear();
+ cache.clear();
}
public void cacheScriptPack(ScriptPack scriptLeaf, List abcList) {
@@ -340,24 +291,13 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
if (scriptIndex > -1) {
script = abc.script_info[scriptIndex];
}
- boolean found = false;
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == scriptLeaf) {
- found = true;
- break;
- }
- }
- if (!found) {
- cacheKeys.add(scriptLeaf);
+ if (!cache.contains(scriptLeaf)) {
for (int scriptTraitIndex : scriptLeaf.traitIndices) {
hilightedCodeBuf.append(script.traits.traits[scriptTraitIndex].convertPackaged("", abcList, abc, false, false, scriptIndex, -1, true, new ArrayList()));
}
+
hilightedCode = hilightedCodeBuf.toString();
- cacheValues.add(new CachedDecompilation(hilightedCode));
- }
- if (cacheKeys.size() > maxCacheSize) {
- cacheKeys.remove(0);
- cacheValues.remove(0);
+ cache.put(scriptLeaf, new CachedDecompilation(hilightedCode));
}
}
@@ -407,8 +347,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
public void setABC(ABC abc) {
this.abc = abc;
- cacheKeys.clear();
- cacheValues.clear();
+ cache.clear();
setText("");
}
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
index 9b0dc2da3..4705aa561 100644
--- a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
+++ b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java
@@ -19,8 +19,6 @@ package com.jpexs.decompiler.flash.action.gui;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.Main;
import com.jpexs.decompiler.flash.SWF;
-import com.jpexs.decompiler.flash.abc.ScriptPack;
-import com.jpexs.decompiler.flash.abc.gui.DecompiledEditorPane;
import com.jpexs.decompiler.flash.abc.gui.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionGraph;
@@ -32,6 +30,7 @@ import com.jpexs.decompiler.flash.gui.GraphFrame;
import com.jpexs.decompiler.flash.gui.TagNode;
import com.jpexs.decompiler.flash.gui.TagTreeModel;
import com.jpexs.decompiler.flash.gui.View;
+import com.jpexs.decompiler.flash.helpers.Cache;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.helpers.Highlighting;
import com.jpexs.decompiler.flash.tags.Tag;
@@ -46,8 +45,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
+import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@@ -66,7 +65,6 @@ import javax.swing.event.CaretListener;
import javax.swing.tree.TreePath;
import jsyntaxpane.DefaultSyntaxKit;
import jsyntaxpane.actions.DocumentSearchData;
-import jsyntaxpane.actions.gui.QuickFindDialog;
public class ActionPanel extends JPanel implements ActionListener {
@@ -107,51 +105,21 @@ public class ActionPanel extends JPanel implements ActionListener {
private int foundPos = 0;
private JLabel searchForLabel;
private String searchFor;
- private List cacheKeys = new LinkedList();
- private List cacheValues = new LinkedList();
- //private HashMap cache = new HashMap();
private boolean searchIgnoreCase;
private boolean searchRegexp;
+ private Cache cache = new Cache();
private CachedScript getCached(ASMSource pack) {
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == pack) {
- return cacheValues.get(i);
- }
- }
- return null;
+ return (CachedScript) cache.get(pack);
}
private void cacheScript(ASMSource src) {
- int maxCacheSize = 20;
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == src) {
- return;
- }
- }
- List as = src.getActions(SWF.DEFAULT_VERSION);
- String s = com.jpexs.decompiler.flash.action.Action.actionsToSource(as, SWF.DEFAULT_VERSION);
- List hilights = Highlighting.getInstrHighlights(s);
- String srcNoHex = Highlighting.stripHilights(s);
- cacheKeys.add(src);
- cacheValues.add(new CachedScript(srcNoHex, hilights, as));
- if (cacheKeys.size() > maxCacheSize) {
- cacheKeys.remove(0);
- cacheValues.remove(0);
- }
-
- }
-
- private static class CachedScript {
-
- public String text;
- List hilights;
- List actions;
-
- public CachedScript(String text, List hilights, List actions) {
- this.text = text;
- this.hilights = hilights;
- this.actions = actions;
+ if (!cache.contains(src)) {
+ List as = src.getActions(SWF.DEFAULT_VERSION);
+ String s = com.jpexs.decompiler.flash.action.Action.actionsToSource(as, SWF.DEFAULT_VERSION);
+ List hilights = Highlighting.getInstrHighlights(s);
+ String srcNoHex = Highlighting.stripHilights(s);
+ cache.put(src, new CachedScript(srcNoHex, hilights));
}
}
@@ -225,7 +193,9 @@ public class ActionPanel extends JPanel implements ActionListener {
editor.setText(stripped);
for (Highlighting h : disassembledHilights) {
if (h.offset == offset) {
- editor.setCaretPosition(h.startPos);
+ if (h.startPos <= editor.getText().length()) {
+ editor.setCaretPosition(h.startPos);
+ }
break;
}
}
@@ -280,7 +250,7 @@ public class ActionPanel extends JPanel implements ActionListener {
}
cacheScript(asm);
CachedScript sc = getCached(asm);
- lastCode = sc.actions;
+ lastCode = asm.getActions(SWF.DEFAULT_VERSION);
decompiledHilights = sc.hilights;
lastDecompiled = sc.text;
stripped = lastDecompiled;
@@ -652,26 +622,18 @@ public class ActionPanel extends JPanel implements ActionListener {
Main.mainFrame.tagTree.setSelectionPath(tp);
Main.mainFrame.tagTree.scrollPathToVisible(tp);
decompiledEditor.setCaretPosition(0);
- try {
- Thread.sleep(100);
- } catch (InterruptedException ex) {
- Logger.getLogger(ActionPanel.class.getName()).log(Level.SEVERE, null, ex);
- }
- DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledEditor);
- dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase);
- QuickFindDialog quickFindDlg = new QuickFindDialog(decompiledEditor, dsd);
- quickFindDlg.setRegularExpression(searchRegexp);
- quickFindDlg.setIgnoreCase(searchIgnoreCase);
- quickFindDlg.showFor(decompiledEditor);
+ java.util.Timer t = new java.util.Timer();
+ t.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledEditor);
+ dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase);
+ dsd.showQuickFindDialogEx(decompiledEditor, searchIgnoreCase, searchRegexp);
+ }
+ }, 1000);
}
private void uncache(ASMSource pack) {
- for (int i = 0; i < cacheKeys.size(); i++) {
- if (cacheKeys.get(i) == pack) {
- cacheValues.remove(i);
- cacheKeys.remove(i);
- break;
- }
- }
+ cache.remove(pack);
}
}
diff --git a/trunk/src/com/jpexs/decompiler/flash/action/gui/CachedScript.java b/trunk/src/com/jpexs/decompiler/flash/action/gui/CachedScript.java
new file mode 100644
index 000000000..cca4fa7f2
--- /dev/null
+++ b/trunk/src/com/jpexs/decompiler/flash/action/gui/CachedScript.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 JPEXS
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.jpexs.decompiler.flash.action.gui;
+
+import com.jpexs.decompiler.flash.helpers.Highlighting;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ *
+ * @author JPEXS
+ */
+public class CachedScript implements Serializable {
+
+ public String text;
+ List hilights;
+
+ public CachedScript(String text, List hilights) {
+ this.text = text;
+ this.hilights = hilights;
+ }
+}
diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/Cache.java b/trunk/src/com/jpexs/decompiler/flash/helpers/Cache.java
new file mode 100644
index 000000000..4219bd550
--- /dev/null
+++ b/trunk/src/com/jpexs/decompiler/flash/helpers/Cache.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 JPEXS
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.jpexs.decompiler.flash.helpers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author JPEXS
+ */
+public class Cache {
+
+ private Map