Skip to content

Commit

Permalink
reuse the fields array
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Sep 3, 2024
1 parent c6b1964 commit 83741ec
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ private EnumTypeAdapter(final Class<T> classOfT) {
// Uses reflection to find enum constants to work around name mismatches for obfuscated
// classes
Field[] fields = classOfT.getDeclaredFields();
Field[] constantFields = new Field[fields.length];
int constantCount = 0;
for (Field f : fields) {
// Filter out non-constant fields, replacing elements as we go
if (f.isEnumConstant()) {
constantFields[constantCount++] = f;
fields[constantCount++] = f;
}
}

// Truncate the constantFields array
constantFields = Arrays.copyOf(constantFields, constantCount);
// Trim the array to the new length
fields = Arrays.copyOf(fields, constantCount);

AccessibleObject.setAccessible(constantFields, true);
AccessibleObject.setAccessible(fields, true);

for (Field constantField : constantFields) {
for (Field constantField : fields) {
@SuppressWarnings("unchecked")
T constant = (T) constantField.get(null);
String name = constant.name();
Expand Down

0 comments on commit 83741ec

Please sign in to comment.