mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-29 22:04:25 +02:00
improve memory usage
This commit is contained in:
parent
ac7c49c22b
commit
b61611ab68
@ -29,7 +29,7 @@ import java.util.Iterator;
|
||||
public class EntryGroup extends ItemGroup<Entry> {
|
||||
private final int resourceId;
|
||||
public EntryGroup(int resId) {
|
||||
super(create(), String.format("0x%08x", resId));
|
||||
super(ARRAY_CREATOR, String.valueOf(resId));
|
||||
this.resourceId=resId;
|
||||
}
|
||||
public int getResourceId(){
|
||||
@ -220,6 +220,10 @@ public class EntryGroup extends ItemGroup<Entry> {
|
||||
return packageBlock.getSpecStringPool();
|
||||
}
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return resourceId;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
Entry entry =pickOne();
|
||||
if(entry ==null){
|
||||
@ -227,8 +231,8 @@ public class EntryGroup extends ItemGroup<Entry> {
|
||||
}
|
||||
return super.toString()+"{"+ entry.toString()+"}";
|
||||
}
|
||||
private static BlockArrayCreator<Entry> create(){
|
||||
return new BlockArrayCreator<Entry>(){
|
||||
|
||||
private static final BlockArrayCreator<Entry> ARRAY_CREATOR = new BlockArrayCreator<Entry>(){
|
||||
@Override
|
||||
public Entry newInstance() {
|
||||
return new Entry();
|
||||
@ -239,6 +243,5 @@ public class EntryGroup extends ItemGroup<Entry> {
|
||||
return new Entry[len];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,12 +27,10 @@ import java.util.Objects;
|
||||
private final BlockArrayCreator<T> mBlockArrayCreator;
|
||||
private final String name;
|
||||
private T[] items;
|
||||
private final int hashCode;
|
||||
public ItemGroup(BlockArrayCreator<T> blockArrayCreator, String name){
|
||||
this.mBlockArrayCreator=blockArrayCreator;
|
||||
this.name=name;
|
||||
this.items=blockArrayCreator.newInstance(0);
|
||||
this.hashCode = Objects.hash(getClass(), name);
|
||||
}
|
||||
public Iterator<T> iterator(){
|
||||
return iterator(false);
|
||||
@ -139,12 +137,12 @@ import java.util.Objects;
|
||||
}
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return hashCode;
|
||||
return 31 * name.hashCode();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof StringGroup){
|
||||
return hashCode==obj.hashCode();
|
||||
return hashCode()==obj.hashCode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -28,18 +28,16 @@ import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class StringItem extends BlockItem implements JSONConvert<JSONObject> {
|
||||
private String mCache;
|
||||
private boolean mUtf8;
|
||||
private final List<ReferenceItem> mReferencedList;
|
||||
private final Set<ReferenceItem> mReferencedList;
|
||||
public StringItem(boolean utf8) {
|
||||
super(0);
|
||||
this.mUtf8=utf8;
|
||||
this.mReferencedList=new ArrayList<>();
|
||||
this.mReferencedList = new HashSet<>();
|
||||
}
|
||||
public boolean removeReference(ReferenceItem ref){
|
||||
return mReferencedList.remove(ref);
|
||||
@ -53,7 +51,7 @@ public class StringItem extends BlockItem implements JSONConvert<JSONObject> {
|
||||
public boolean hasReference(){
|
||||
return mReferencedList.size()>0;
|
||||
}
|
||||
public List<ReferenceItem> getReferencedList(){
|
||||
public Collection<ReferenceItem> getReferencedList(){
|
||||
return mReferencedList;
|
||||
}
|
||||
public void addReference(ReferenceItem ref){
|
||||
@ -62,7 +60,7 @@ public class StringItem extends BlockItem implements JSONConvert<JSONObject> {
|
||||
}
|
||||
}
|
||||
public void addReferenceIfAbsent(ReferenceItem ref){
|
||||
if(ref!=null && !mReferencedList.contains(ref)){
|
||||
if(ref!=null){
|
||||
mReferencedList.add(ref);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user