diff options
Diffstat (limited to 'src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java')
-rw-r--r-- | src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java b/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java index 7cbdf9b74..a4f49122e 100644 --- a/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java +++ b/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java @@ -9,10 +9,12 @@ import com.android.tools.r8.graph.DexEncodedField; import com.android.tools.r8.graph.DexField; import com.android.tools.r8.graph.DexString; import com.android.tools.r8.graph.DexType; +import com.android.tools.r8.shaking.ProguardConfiguration; import com.android.tools.r8.shaking.RootSetBuilder.RootSet; import com.android.tools.r8.utils.InternalOptions; import com.android.tools.r8.utils.Timing; import java.util.Map; +import java.util.function.Function; class FieldNameMinifier extends MemberNameMinifier<DexField, DexType> { @@ -20,6 +22,17 @@ class FieldNameMinifier extends MemberNameMinifier<DexField, DexType> { super(appInfo, rootSet, options); } + @Override + Function<DexType, ?> getKeyTransform(ProguardConfiguration config) { + if (config.isOverloadAggressively()) { + // Use the type as the key, hence reuse names per type. + return a -> a; + } else { + // Always use the same key, hence do not reuse names per type. + return a -> Void.class; + } + } + Map<DexField, DexString> computeRenaming(Timing timing) { // Reserve names in all classes first. We do this in subtyping order so we do not // shadow a reserved field in subclasses. While there is no concept of virtual field @@ -41,19 +54,19 @@ class FieldNameMinifier extends MemberNameMinifier<DexField, DexType> { return renaming; } - private void reserveNamesInSubtypes(DexType type, NamingState<DexType> state) { + private void reserveNamesInSubtypes(DexType type, NamingState<DexType, ?> state) { DexClass holder = appInfo.definitionFor(type); if (holder == null) { return; } - NamingState<DexType> newState = computeStateIfAbsent(type, t -> state.createChild()); + NamingState<DexType, ?> newState = computeStateIfAbsent(type, t -> state.createChild()); holder.forEachField(field -> reserveFieldName(field, newState, holder.isLibraryClass())); type.forAllExtendsSubtypes(subtype -> reserveNamesInSubtypes(subtype, newState)); } private void reserveFieldName( DexEncodedField encodedField, - NamingState<DexType> state, + NamingState<DexType, ?> state, boolean isLibrary) { if (isLibrary || rootSet.noObfuscation.contains(encodedField)) { DexField field = encodedField.field; @@ -66,13 +79,13 @@ class FieldNameMinifier extends MemberNameMinifier<DexField, DexType> { if (clazz == null) { return; } - NamingState<DexType> state = getState(clazz.type); + NamingState<DexType, ?> state = getState(clazz.type); assert state != null; clazz.forEachField(field -> renameField(field, state)); type.forAllExtendsSubtypes(this::renameFieldsInSubtypes); } - private void renameField(DexEncodedField encodedField, NamingState<DexType> state) { + private void renameField(DexEncodedField encodedField, NamingState<DexType, ?> state) { DexField field = encodedField.field; if (!state.isReserved(field.name, field.type)) { renaming.put(field, state.assignNewNameFor(field.name, field.type, false)); |