do not instantiate millions of ArrayList

This commit is contained in:
honfika@gmail.com
2015-07-09 13:03:29 +02:00
parent 42a8fc4c22
commit 9415a7a115
5 changed files with 33 additions and 19 deletions

View File

@@ -52,8 +52,8 @@ public class SwapIns extends InstructionDefinition {
GraphTargetItem o2 = stack.pop();
stack.push(o1);
stack.push(o2);
o1.moreSrc.add(new GraphSourceItemPos(ins, 0));
o2.moreSrc.add(new GraphSourceItemPos(ins, 0));
o1.getMoreSrc().add(new GraphSourceItemPos(ins, 0));
o2.getMoreSrc().add(new GraphSourceItemPos(ins, 0));
}
@Override

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library 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
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
@@ -39,6 +39,6 @@ public class ActionPushDuplicate extends Action {
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem value = stack.peek();
stack.push(new DuplicateItem(this, value));
value.moreSrc.add(new GraphSourceItemPos(this, 0));
value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
}
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library 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
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.action.Action;
@@ -39,7 +40,7 @@ public class ActionStackSwap extends Action {
GraphTargetItem b = stack.pop();
stack.push(a);
stack.push(b);
stack.push(b);
a.moreSrc.add(new GraphSourceItemPos(this, 0));
a.getMoreSrc().add(new GraphSourceItemPos(this, 0));
b.getMoreSrc().add(new GraphSourceItemPos(this, 0));
}
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library 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
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.SWFInputStream;
@@ -82,7 +83,7 @@ public class ActionStoreRegister extends Action implements StoreTypeAction {
if (regNames.containsKey(registerNumber)) {
rn.name = regNames.get(registerNumber);
}
}
value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
if (variables.containsKey("__register" + registerNumber)) {
if (variables.get("__register" + registerNumber) instanceof TemporaryRegister) {
variables.remove("__register" + registerNumber);

View File

@@ -76,7 +76,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
protected int precedence;
public List<GraphSourceItemPos> moreSrc = new ArrayList<>();
private List<GraphSourceItemPos> moreSrc;
public GraphPart firstPart;
@@ -122,6 +122,14 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
return src;
}
public List<GraphSourceItemPos> getMoreSrc() {
if (moreSrc == null) {
moreSrc = new ArrayList<>()
}
return moreSrc;
}
protected HighlightData getSrcData() {
if (srcData == null) {
srcData = new HighlightData();
@@ -133,10 +141,14 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = new ArrayList<>();
ret.add(new GraphSourceItemPos(src, pos));
ret.addAll(moreSrc);
if (moreSrc != null) {
ret.addAll(moreSrc);
}
if (value != null) {
ret.addAll(value.getNeededSources());
}
return ret;
}