From 2e370c9bd4dc3cd60ca5a32429f026001d7c54ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 16 Dec 2012 18:55:00 +0100 Subject: [PATCH] Position cache (Faster decompiling) Not clearing killed registers --- .../com/jpexs/asdec/abc/avm2/AVM2Code.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java index 1c6c0549e..5959da8f3 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java @@ -797,27 +797,36 @@ public class AVM2Code { return ret; } + private boolean cacheActual=false; + private List posCache; + private void buildCache() + { + posCache=new ArrayList(); + long a = 0; + for (int i = 0; i < code.size(); i++) { + posCache.add(a); + a += code.get(i).getBytes().length; + } + posCache.add(a); + cacheActual=true; + } + public int adr2pos(long address) throws ConvertException { - int a = 0; - for (int i = 0; i < code.size(); i++) { - if (a == address) { - return i; - } - a += code.get(i).getBytes().length; - } - if (a == address) { - return code.size(); - } - throw new ConvertException("Bad jump", -1); + if(!cacheActual){ + buildCache(); + } + int ret=posCache.indexOf(address); + if(ret == -1) { + throw new ConvertException("Bad jump", -1); + } + return ret; } public int pos2adr(int pos) { - int a = 0; - for (int i = 0; i < pos; i++) { - a += code.get(i).getBytes().length; - } - - return a; + if(!cacheActual){ + buildCache(); + } + return posCache.get(pos).intValue(); } private static String listToString(List stack, ConstantPool constants) { @@ -1713,7 +1722,7 @@ public HashMap getLocalRegNamesFromDebug(ABC abc){ } if (debugMode) System.out.println("CLOSE SubSource:" + start + "-" + end + " " + code.get(start).toString() + " to " + code.get(end).toString()); - clearKilledAssigments(output); + //clearKilledAssigments(output); return new ConvertOutput(stack, output); } catch (ConvertException cex) { throw cex; @@ -2349,7 +2358,7 @@ public HashMap getLocalRegNamesFromDebug(ABC abc){ } catch (ConvertException ex1) { } - } + } return stats; } }