mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-19 03:49:19 +00:00
more efficient turbo transformer
This commit is contained in:
5 files changed
+55
-24
No files matched your search
@@ -32,22 +32,26 @@ import java.util.List;
|
||||
public class TransformerUtil {
|
||||
private static final Logger LOG = LogManager.getLogger("ASM");
|
||||
public static boolean executeTransformers(String transformedName, ClassNodeHandle handle, List<TurboClassTransformer> transformers) {
|
||||
boolean didTransformation = false;
|
||||
boolean modified = false;
|
||||
for (val transformer: transformers) {
|
||||
try {
|
||||
if (transformer.shouldTransformClass(transformedName, handle)) {
|
||||
if (!didTransformation) {
|
||||
LOG.debug("Transforming {}!", transformedName);
|
||||
LOG.trace("Transforming {} with {}, owner: {}", transformedName, transformer.name(), transformer.owner());
|
||||
if (transformer.transformClass(transformedName, handle)) {
|
||||
LOG.trace("Transformed.");
|
||||
modified = true;
|
||||
} else {
|
||||
LOG.trace("No change.");
|
||||
}
|
||||
didTransformation = true;
|
||||
transformer.transformClass(transformedName, handle);
|
||||
LOG.debug("Successfully transformed class {} with {}, owner: {}", transformedName, transformer.name(), transformer.owner());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to transform class {} with {}, owner: {}", transformedName, transformer.name(), transformer.owner());
|
||||
LOG.error("Exception stacktrace:", e);
|
||||
}
|
||||
}
|
||||
return didTransformation;
|
||||
if (modified) {
|
||||
LOG.trace("Transformed class {}", transformedName);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,9 @@ public interface TurboClassTransformer {
|
||||
* (Optionally) transform a given class. No ClassReader flags are used for maximum efficiency, so stack frames are not expanded.
|
||||
* @param className The name of the transformed class (in the dot-separated format).
|
||||
* @param classNode The handle to the lazily ASM-parsed class to modify, and metadata used for class writing.
|
||||
* @return True if the class has been modified in any way by this transformer. If all transformers return false,
|
||||
* then the ClassNode instance will not be re-serialized.
|
||||
*/
|
||||
@Expose
|
||||
void transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode);
|
||||
boolean transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode);
|
||||
}
|
||||
Reference in new issue
Block a user