Skip to content

Commit

Permalink
[DEX] Faster usage search
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Dec 14, 2024
1 parent 5239dd0 commit a40bf2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/reandroid/dex/common/IdDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,25 @@
package com.reandroid.dex.common;

import com.reandroid.dex.id.IdItem;
import com.reandroid.dex.key.Key;
import com.reandroid.dex.program.AccessibleProgram;

public interface IdDefinition<T extends IdItem> extends AccessibleProgram {
import java.util.Iterator;

public interface IdDefinition<T extends IdItem> extends AccessibleProgram, IdUsageIterator {

T getId();

@Override
default boolean uses(Key key) {
IdItem id = getId();
Iterator<IdItem> iterator = usedIds();
while (iterator.hasNext()) {
IdItem idItem = iterator.next();
if (!id.equals(idItem) && key.equals(idItem.getKey())) {
return true;
}
}
return false;
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/reandroid/dex/data/FieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.reandroid.dex.smali.model.Smali;
import com.reandroid.dex.smali.model.SmaliField;
import com.reandroid.dex.smali.SmaliWriter;
import com.reandroid.utils.collection.CombiningIterator;
import com.reandroid.utils.collection.SingleIterator;

import java.io.IOException;
Expand Down Expand Up @@ -126,14 +127,18 @@ public boolean isInitializedInStaticConstructor() {
}
return false;
}

@Override
public Iterator<IdItem> usedIds(){
public Iterator<IdItem> usedIds() {
return SingleIterator.of(getId());
}

@Override
void onRemove() {
super.onRemove();
public boolean uses(Key key) {
return key.equals(getStaticValue());
}
@Override
public Iterator<Key> usedKeys() {
return CombiningIterator.singleOne(getKey(), SingleIterator.of(getStaticValue()));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/dex/model/DexDeclaration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean uses(Key key) {
if(getKey().equals(key)){
return false;
}
return getId().uses(key);
return getDefinition().uses(key);
}
public boolean isAccessibleTo(TypeKey typeKey) {
if(this.getDefining().equals(typeKey)){
Expand Down

0 comments on commit a40bf2d

Please sign in to comment.