mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 04:10:13 +02:00
Merge pull request #8 from izzytwosheds/encoded_array_sort
Sorting items in encoded_array to match the order of fields.
This commit is contained in:
commit
1803b576fd
@ -114,6 +114,13 @@ public class EncodedArrayPool {
|
||||
private final Set<? extends Field> fields;
|
||||
private final int size;
|
||||
|
||||
private static class FieldComparator implements Comparator<Field> {
|
||||
@Override
|
||||
public int compare(Field o1, Field o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Function<Field, EncodedValue> GET_INITIAL_VALUE =
|
||||
new Function<Field, EncodedValue>() {
|
||||
@Override
|
||||
@ -133,13 +140,13 @@ public class EncodedArrayPool {
|
||||
|
||||
@Nullable
|
||||
public static Key of(@Nonnull ClassDef classDef) {
|
||||
Set<? extends Field> fields = classDef.getFields();
|
||||
|
||||
Iterable<? extends Field> staticFields = FluentIterable.from(classDef.getFields()).filter(IS_STATIC_FIELD);
|
||||
int lastIndex = CollectionUtils.lastIndexOf(staticFields, HAS_INITIALIZER);
|
||||
Set<? extends Field> staticFieldsSorted = FluentIterable.from(classDef.getFields())
|
||||
.filter(IS_STATIC_FIELD)
|
||||
.toSortedSet(new FieldComparator());
|
||||
|
||||
int lastIndex = CollectionUtils.lastIndexOf(staticFieldsSorted, HAS_INITIALIZER);
|
||||
if (lastIndex > -1) {
|
||||
return new Key(fields, lastIndex+1);
|
||||
return new Key(staticFieldsSorted, lastIndex+1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -151,7 +158,6 @@ public class EncodedArrayPool {
|
||||
@Nonnull
|
||||
public Iterable<EncodedValue> getElements() {
|
||||
return FluentIterable.from(fields)
|
||||
.filter(IS_STATIC_FIELD)
|
||||
.limit(size)
|
||||
.transform(GET_INITIAL_VALUE);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user