Optimize RemappedRuntimeInheritanceProvider to not traverse inheritance if not remapped
Used to lookup the inheritance if every single class - now will return null and allow other inheritance providers to answer instead. Consequentially mapTypeName() has been enhanced to accept a 'default' type name: pass the same typeName to 'pass through' unmapped names, or null if you want to distinguish between unmapped and mapped names, as RemappedRuntimeInheritanceProvider does.
This commit is contained in:
parent
718ffc8bb5
commit
4499220c61
@ -57,20 +57,19 @@ public class JarRemapper extends Remapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String map(String typeName) {
|
public String map(String typeName) {
|
||||||
return mapTypeName(typeName, jarMapping.packages, jarMapping.classes);
|
return mapTypeName(typeName, jarMapping.packages, jarMapping.classes, typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String mapTypeName(String typeName, Map<String, String> packageMap, Map<String, String> classMap) {
|
public static String mapTypeName(String typeName, Map<String, String> packageMap, Map<String, String> classMap, String defaultIfUnmapped) {
|
||||||
int index = typeName.indexOf('$');
|
int index = typeName.indexOf('$');
|
||||||
String key = (index == -1) ? typeName : typeName.substring(0, index);
|
String key = (index == -1) ? typeName : typeName.substring(0, index);
|
||||||
String mapped = mapClassName(key, packageMap, classMap);
|
String mapped = mapClassName(key, packageMap, classMap);
|
||||||
|
|
||||||
return mapped != null ? mapped + (index == -1 ? "" : typeName.substring(index, typeName.length())) : typeName;
|
return mapped != null ? mapped + (index == -1 ? "" : typeName.substring(index, typeName.length())) : defaultIfUnmapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to map a class name by package (prefix) or class (exact)
|
* Helper method to map a class name by package (prefix) or class (exact)
|
||||||
* map
|
|
||||||
*/
|
*/
|
||||||
private static String mapClassName(String className, Map<String, String> packageMap, Map<String, String> classMap) {
|
private static String mapClassName(String className, Map<String, String> packageMap, Map<String, String> classMap) {
|
||||||
if (packageMap != null) {
|
if (packageMap != null) {
|
||||||
|
@ -57,7 +57,7 @@ public class MethodDescriptorTransformer {
|
|||||||
String className = rest.substring(1, end);
|
String className = rest.substring(1, end);
|
||||||
i += className.length() + 1;
|
i += className.length() + 1;
|
||||||
|
|
||||||
String newClassName = JarRemapper.mapTypeName(className, packageMap, classMap);
|
String newClassName = JarRemapper.mapTypeName(className, packageMap, classMap, className);
|
||||||
|
|
||||||
output.append("L").append(newClassName).append(";");
|
output.append("L").append(newClassName).append(";");
|
||||||
break;
|
break;
|
||||||
|
@ -31,7 +31,14 @@ public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvid
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getParents(String before) {
|
public List<String> getParents(String before) {
|
||||||
// Remap the input (example: cb -> obf)
|
// Remap the input (example: cb -> obf)
|
||||||
String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes);
|
// If the type is not mapped, return immediately
|
||||||
|
String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes, null);
|
||||||
|
if (after == null) {
|
||||||
|
if (verbose) {
|
||||||
|
System.out.println("RemappedRuntimeInheritanceProvider doesn't know about "+before);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
System.out.println("RemappedRuntimeInheritanceProvider getParents "+before+" -> "+after);
|
System.out.println("RemappedRuntimeInheritanceProvider getParents "+before+" -> "+after);
|
||||||
@ -48,7 +55,7 @@ public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvid
|
|||||||
// Un-remap the output (example: obf -> cb)
|
// Un-remap the output (example: obf -> cb)
|
||||||
List<String> afterParents = new ArrayList<String>();
|
List<String> afterParents = new ArrayList<String>();
|
||||||
for (String beforeParent : beforeParents) {
|
for (String beforeParent : beforeParents) {
|
||||||
String afterParent = JarRemapper.mapTypeName(beforeParent, inverseJarMapping.packages, inverseJarMapping.classes);
|
String afterParent = JarRemapper.mapTypeName(beforeParent, inverseJarMapping.packages, inverseJarMapping.classes, beforeParent);
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
System.out.println("- " + beforeParent + " -> " + afterParent);
|
System.out.println("- " + beforeParent + " -> " + afterParent);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user