do not instantiate millions of HighlightData

This commit is contained in:
honfika@gmail.com
2015-07-09 10:31:50 +02:00
parent c8db079e8e
commit 0437e95b4f
16 changed files with 54 additions and 35 deletions

View File

@@ -756,9 +756,9 @@ public class AVM2Graph extends Graph {
SetTypeAVM2Item sti = (SetTypeAVM2Item) w.commands.remove(0);
GraphTargetItem gti = sti.getValue().getNotCoerced();
if (gti instanceof NextValueAVM2Item) {
return new ForEachInAVM2Item(w.src, w.loop, new InAVM2Item(hn.instruction, sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands);
return new ForEachInAVM2Item(w.src, w.loop, new InAVM2Item(hn.getInstruction(), sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands);
} else if (gti instanceof NextNameAVM2Item) {
return new ForInAVM2Item(w.src, w.loop, new InAVM2Item(hn.instruction, sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands);
return new ForInAVM2Item(w.src, w.loop, new InAVM2Item(hn.getInstruction(), sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands);
}
}
}

View File

@@ -129,7 +129,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
c.args.clear();
List<GraphTargetItem> vals = new ArrayList<>();
vals.add(value);
c.object = new InitVectorAVM2Item(c.instruction, at.params.get(0), vals);
c.object = new InitVectorAVM2Item(c.getInstruction(), at.params.get(0), vals);
return;
} else if (c.object instanceof InitVectorAVM2Item) {
InitVectorAVM2Item iv = (InitVectorAVM2Item) c.object;

View File

@@ -35,9 +35,7 @@ import java.util.List;
public abstract class AVM2Item extends GraphTargetItem {
public AVM2Instruction instruction;
public boolean hidden = false;
private AVM2Instruction instruction;
public AVM2Item(GraphSourceItem instruction, int precedence) {
super(instruction, precedence);
@@ -46,6 +44,10 @@ public abstract class AVM2Item extends GraphTargetItem {
}
}
public AVM2Instruction getInstruction() {
return instruction;
}
@Override
public boolean needsSemicolon() {
return true;

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.abc.avm2.model;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
@@ -33,9 +34,8 @@ public class GetLexAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
String localName = propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
String localName = propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
getSrcData().localName = localName;
return writer.append(propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
}

View File

@@ -40,8 +40,8 @@ public class GetSlotAVM2Item extends AVM2Item {
if (slotName == null) {
return writer.append("/*UnknownSlot*/");
}
srcData.localName = getNameAsStr(localData);
getSrcData().localName = getNameAsStr(localData);
return writer.append(slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
}

View File

@@ -46,7 +46,7 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A
@Override
public GraphTargetItem getObject() {
return new GetPropertyAVM2Item(instruction, object, propertyName);
return new GetPropertyAVM2Item(getInstruction(), object, propertyName);
}
@Override

View File

@@ -65,8 +65,9 @@ public class LocalRegAVM2Item extends AVM2Item {
if (computedValue instanceof FilterAVM2Item) {
return computedValue.toString(writer, localData);
}
String localName = localRegName(localData.localRegNames, regIndex);
srcData.localName = localName;
getSrcData().localName = localName;
return writer.append(localName);
}

View File

@@ -48,14 +48,14 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
String localName = localRegName(localData.localRegNames, regIndex);
srcData.localName = localName;
getSrcData().localName = localName;
writer.append(localName).append(" = ");
return value.toString(writer, localData);
}
@Override
public GraphTargetItem getObject() {
return new LocalRegAVM2Item(instruction, regIndex, null);
return new LocalRegAVM2Item(getInstruction(), regIndex, null);
}
@Override

View File

@@ -60,7 +60,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As
@Override
public GraphTargetItem getObject() {
return new GetPropertyAVM2Item(instruction, object, propertyName);
return new GetPropertyAVM2Item(getInstruction(), object, propertyName);
}
@Override

View File

@@ -46,7 +46,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
srcData.localName = slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
getSrcData().localName = slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
getName(writer, localData);
writer.append(" = ");
return value.toString(writer, localData);
@@ -65,7 +65,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
@Override
public GraphTargetItem getObject() {
return new GetSlotAVM2Item(instruction, scope, slotName);
return new GetSlotAVM2Item(getInstruction(), scope, slotName);
}
@Override

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.abc.avm2.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -35,7 +36,7 @@ public class ThisAVM2Item extends AVM2Item {
public ThisAVM2Item(GraphSourceItem instruction, Multiname className) {
super(instruction, PRECEDENCE_PRIMARY);
this.className = className;
this.className = className;
getSrcData().localName = "this";
}
@Override

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetSlotAVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -54,6 +55,7 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof LocalRegAVM2Item) { //for..in
LocalRegAVM2Item lti = (LocalRegAVM2Item) assignment;
String localName = localRegName(localData.localRegNames, lti.regIndex);
HighlightData srcData = getSrcData();
srcData.localName = localName;
srcData.declaration = true;
srcData.declaredType = "*";
@@ -64,6 +66,7 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof GetSlotAVM2Item) { //for..in
GetSlotAVM2Item sti = (GetSlotAVM2Item) assignment;
HighlightData srcData = getSrcData();
srcData.localName = sti.getNameAsStr(localData);
srcData.declaration = true;
srcData.declaredType = "*";
@@ -75,6 +78,7 @@ public class DeclarationAVM2Item extends AVM2Item {
if (assignment instanceof SetLocalAVM2Item) {
SetLocalAVM2Item lti = (SetLocalAVM2Item) assignment;
String localName = localRegName(localData.localRegNames, lti.regIndex);
HighlightData srcData = getSrcData();
srcData.localName = localName;
srcData.declaration = true;
@@ -95,6 +99,7 @@ public class DeclarationAVM2Item extends AVM2Item {
}
if (assignment instanceof SetSlotAVM2Item) {
SetSlotAVM2Item ssti = (SetSlotAVM2Item) assignment;
HighlightData srcData = getSrcData();
srcData.localName = ssti.getNameAsStr(localData);
srcData.declaration = true;
srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName.toPrintableString() : "*";

View File

@@ -90,6 +90,7 @@ public class TryAVM2Item extends AVM2Item implements Block {
if (localName.isEmpty()) {
localName = finCatchName;
}
HighlightData data = new HighlightData();
data.localName = localName;
data.declaration = true;

View File

@@ -109,7 +109,7 @@ public abstract class GraphTextWriter {
}
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue) {
return hilightSpecial(text, type, Integer.toString(specialValue), new HighlightData());
return hilightSpecial(text, type, Integer.toString(specialValue), null);
}
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue, HighlightData data) {
@@ -117,7 +117,7 @@ public abstract class GraphTextWriter {
}
public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue) {
return hilightSpecial(text, type, specialValue, new HighlightData());
return hilightSpecial(text, type, specialValue, null);
}
protected GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) {

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.helpers.hilight;
import java.io.Serializable;
@@ -44,6 +45,9 @@ public class HighlightData implements Cloneable, Serializable {
}
public void merge(HighlightData data) {
if (data == null) {
return;
}
if (data.declaration) {
declaration = data.declaration;
}

View File

@@ -82,7 +82,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
public GraphTargetItem value;
protected HighlightData srcData = new HighlightData();
private HighlightData srcData;
public int getLine() {
if (src != null) {
@@ -310,10 +310,15 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
}
}
/*public GraphTargetItem invert() {
return invert(null);
}*/
public GraphTargetItem invert(GraphSourceItem src) {
return new NotItem(src, this);
}
protected HighlightData getSrcData() {
if (srcData == null) {
srcData = new HighlightData();
}
return srcData;
}
}