reduced memory usage - use HashMap for attributes
This commit is contained in:
@@ -21,22 +21,27 @@ import org.jetbrains.java.decompiler.struct.attr.StructLocalVariableTableAttribu
|
||||
import org.jetbrains.java.decompiler.struct.attr.StructLocalVariableTypeTableAttribute;
|
||||
import org.jetbrains.java.decompiler.struct.consts.ConstantPool;
|
||||
import org.jetbrains.java.decompiler.util.DataInputFullStream;
|
||||
import org.jetbrains.java.decompiler.util.VBStyleCollection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class StructMember {
|
||||
|
||||
protected int accessFlags;
|
||||
protected VBStyleCollection<StructGeneralAttribute, String> attributes;
|
||||
protected Map<String, StructGeneralAttribute> attributes;
|
||||
|
||||
|
||||
public int getAccessFlags() {
|
||||
return accessFlags;
|
||||
}
|
||||
|
||||
public VBStyleCollection<StructGeneralAttribute, String> getAttributes() {
|
||||
return attributes;
|
||||
public StructGeneralAttribute getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
public boolean hasAttribute(String name) {
|
||||
return attributes.containsKey(name);
|
||||
}
|
||||
|
||||
public boolean hasModifier(int modifier) {
|
||||
@@ -44,13 +49,13 @@ public class StructMember {
|
||||
}
|
||||
|
||||
public boolean isSynthetic() {
|
||||
return hasModifier(CodeConstants.ACC_SYNTHETIC) || attributes.containsKey(StructGeneralAttribute.ATTRIBUTE_SYNTHETIC);
|
||||
return hasModifier(CodeConstants.ACC_SYNTHETIC) || hasAttribute(StructGeneralAttribute.ATTRIBUTE_SYNTHETIC);
|
||||
}
|
||||
|
||||
protected VBStyleCollection<StructGeneralAttribute, String> readAttributes(DataInputFullStream in, ConstantPool pool) throws IOException {
|
||||
protected Map<String, StructGeneralAttribute> readAttributes(DataInputFullStream in, ConstantPool pool) throws IOException {
|
||||
int length = in.readUnsignedShort();
|
||||
|
||||
VBStyleCollection<StructGeneralAttribute, String> attributes = new VBStyleCollection<>(length);
|
||||
Map<String, StructGeneralAttribute> attributes = new HashMap<>(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int nameIndex = in.readUnsignedShort();
|
||||
String name = pool.getPrimitiveConstant(nameIndex).getString();
|
||||
@@ -60,16 +65,16 @@ public class StructMember {
|
||||
if (attribute != null) {
|
||||
if (StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE.equals(name) && attributes.containsKey(name)) {
|
||||
// merge all variable tables
|
||||
StructLocalVariableTableAttribute table = (StructLocalVariableTableAttribute)attributes.getWithKey(name);
|
||||
StructLocalVariableTableAttribute table = (StructLocalVariableTableAttribute)attributes.get(name);
|
||||
table.add((StructLocalVariableTableAttribute)attribute);
|
||||
}
|
||||
else if (StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TYPE_TABLE.equals(name) && attributes.containsKey(name)) {
|
||||
// merge all variable tables
|
||||
StructLocalVariableTypeTableAttribute table = (StructLocalVariableTypeTableAttribute)attributes.getWithKey(name);
|
||||
StructLocalVariableTypeTableAttribute table = (StructLocalVariableTypeTableAttribute)attributes.get(name);
|
||||
table.add((StructLocalVariableTypeTableAttribute)attribute);
|
||||
}
|
||||
else {
|
||||
attributes.addWithKey(attribute, attribute.getName());
|
||||
attributes.put(attribute.getName(), attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.java.decompiler.util.VBStyleCollection;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.java.decompiler.code.CodeConstants.*;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class StructMethod extends StructMember {
|
||||
private int codeFullLength = 0;
|
||||
private InstructionSequence seq;
|
||||
private boolean expanded = false;
|
||||
private VBStyleCollection<StructGeneralAttribute, String> codeAttributes;
|
||||
private Map<String, StructGeneralAttribute> codeAttributes;
|
||||
|
||||
public StructMethod(DataInputFullStream in, StructClass clStruct) throws IOException {
|
||||
classStruct = clStruct;
|
||||
@@ -69,7 +70,7 @@ public class StructMethod extends StructMember {
|
||||
|
||||
attributes = readAttributes(in, pool);
|
||||
if (codeAttributes != null) {
|
||||
attributes.addAllWithKey(codeAttributes);
|
||||
attributes.putAll(codeAttributes);
|
||||
codeAttributes = null;
|
||||
}
|
||||
}
|
||||
@@ -391,7 +392,7 @@ public class StructMethod extends StructMember {
|
||||
}
|
||||
|
||||
public StructLocalVariableTableAttribute getLocalVariableAttr() {
|
||||
return (StructLocalVariableTableAttribute)getAttributes().getWithKey(StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
|
||||
return (StructLocalVariableTableAttribute)getAttribute(StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user