mirror of
https://github.com/revanced/smali.git
synced 2025-06-01 05:00:12 +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 Set<? extends Field> fields;
|
||||||
private final int size;
|
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 =
|
private static final Function<Field, EncodedValue> GET_INITIAL_VALUE =
|
||||||
new Function<Field, EncodedValue>() {
|
new Function<Field, EncodedValue>() {
|
||||||
@Override
|
@Override
|
||||||
@ -133,13 +140,13 @@ public class EncodedArrayPool {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Key of(@Nonnull ClassDef classDef) {
|
public static Key of(@Nonnull ClassDef classDef) {
|
||||||
Set<? extends Field> fields = classDef.getFields();
|
Set<? extends Field> staticFieldsSorted = FluentIterable.from(classDef.getFields())
|
||||||
|
.filter(IS_STATIC_FIELD)
|
||||||
Iterable<? extends Field> staticFields = FluentIterable.from(classDef.getFields()).filter(IS_STATIC_FIELD);
|
.toSortedSet(new FieldComparator());
|
||||||
int lastIndex = CollectionUtils.lastIndexOf(staticFields, HAS_INITIALIZER);
|
|
||||||
|
|
||||||
|
int lastIndex = CollectionUtils.lastIndexOf(staticFieldsSorted, HAS_INITIALIZER);
|
||||||
if (lastIndex > -1) {
|
if (lastIndex > -1) {
|
||||||
return new Key(fields, lastIndex+1);
|
return new Key(staticFieldsSorted, lastIndex+1);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -151,7 +158,6 @@ public class EncodedArrayPool {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public Iterable<EncodedValue> getElements() {
|
public Iterable<EncodedValue> getElements() {
|
||||||
return FluentIterable.from(fields)
|
return FluentIterable.from(fields)
|
||||||
.filter(IS_STATIC_FIELD)
|
|
||||||
.limit(size)
|
.limit(size)
|
||||||
.transform(GET_INITIAL_VALUE);
|
.transform(GET_INITIAL_VALUE);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user