From 2f10d83eaa1862f09f4aa3e634b7bda61ab5c26c Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Thu, 9 May 2024 20:32:50 +0100 Subject: [PATCH] Minor optimisations and cleanup, full code audit - Use `IdentityHashMap` for keys of type `Class` - Use `addAll()` instead of a `for` loop `add()` - Use `isEmpty()` instead of `length()`/`size()` comparisons - Reduce eager configuration in build - Other misc. changes --- build.gradle | 16 ++++++++++------ .../tools/agent/MixinAgentClassLoader.java | 3 ++- .../tools/obfuscation/AnnotatedMixin.java | 2 +- .../AnnotatedMixinElementHandler.java | 2 +- .../tools/obfuscation/ObfuscationType.java | 2 +- .../mapping/fg3/MappingProviderTSrg.java | 2 +- .../tools/obfuscation/mirror/TypeHandle.java | 2 +- .../obfuscation/service/ObfuscationServices.java | 2 +- .../service/mojang/LaunchClassLoaderUtil.java | 2 +- .../asm/launch/platform/MixinContainer.java | 4 +--- .../asm/logging/LoggerAdapterAbstract.java | 4 ++-- .../selectors/dynamic/DynamicSelectorDesc.java | 2 +- .../mixin/injection/struct/InjectionInfo.java | 10 ++++------ .../injection/struct/InjectorGroupInfo.java | 2 +- .../asm/mixin/injection/struct/MemberInfo.java | 4 ++-- .../transformer/MixinApplicatorStandard.java | 10 +++++----- .../asm/mixin/transformer/MixinConfig.java | 4 ++-- .../asm/mixin/transformer/MixinInfo.java | 2 +- .../transformer/MixinPreProcessorStandard.java | 2 +- .../mixin/transformer/MixinTargetContext.java | 8 ++++---- .../asm/mixin/transformer/ext/Extensions.java | 6 +++--- .../asm/service/MixinServiceAbstract.java | 3 ++- .../spongepowered/asm/util/ClassSignature.java | 4 ++-- .../spongepowered/asm/util/ConstraintParser.java | 2 +- .../spongepowered/asm/util/LanguageFeatures.java | 2 +- .../org/spongepowered/asm/util/Quantifier.java | 6 +++--- .../spongepowered/asm/util/perf/Profiler.java | 4 +--- .../container/ContainerHandleModLauncher.java | 4 ++-- .../container/ContainerHandleModLauncherEx.java | 2 +- 29 files changed, 59 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index d78ded49d..84a9dc58c 100644 --- a/build.gradle +++ b/build.gradle @@ -332,7 +332,7 @@ checkstyle { } // Source compiler configuration -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.compilerArgs += ['-Xlint:all', '-Xlint:-path', '-proc:none'] options.deprecation = true options.encoding = 'utf8' @@ -342,13 +342,17 @@ def modularityInputs = objects.fileCollection() project.sourceSets.each { set -> { if (set.ext.has("languageVersion")) { - project.tasks[set.compileJavaTaskName].javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(set.ext.languageVersion) + project.tasks.named(set.compileJavaTaskName, JavaCompile) { + it.javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(set.ext.languageVersion) + } } } if (set.ext.has("compatibility")) { - project.tasks[set.compileJavaTaskName].sourceCompatibility = set.ext.compatibility - project.tasks[set.compileJavaTaskName].targetCompatibility = set.ext.compatibility + project.tasks.named(set.compileJavaTaskName, JavaCompile) { + sourceCompatibility = set.ext.compatibility + targetCompatibility = set.ext.compatibility + } } def modularityExcluded = set.ext.has("modularityExcluded") && set.ext.modularityExcluded if (!modularityExcluded) { @@ -370,7 +374,7 @@ compileModularityJava { } if (JavaVersion.current().isJava8Compatible()) { - tasks.withType(Javadoc) { + tasks.withType(Javadoc).configureEach { // disable the crazy super-strict doclint tool in Java 8 options.addStringOption('Xdoclint:syntax', '-quiet') } diff --git a/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java b/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java index 2b4af2709..5c21c4aa1 100644 --- a/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java +++ b/src/agent/java/org/spongepowered/tools/agent/MixinAgentClassLoader.java @@ -25,6 +25,7 @@ package org.spongepowered.tools.agent; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import org.spongepowered.asm.logging.ILogger; @@ -48,7 +49,7 @@ class MixinAgentClassLoader extends ClassLoader { /** * Mapping of mixin mixin classes to their fake classes */ - private Map, byte[]> mixins = new HashMap, byte[]>(); + private Map, byte[]> mixins = new IdentityHashMap, byte[]>(); /** * Mapping that keep track of bytecode for classes that are targeted by diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java index 001bbdfae..47eb112a5 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixin.java @@ -182,7 +182,7 @@ public AnnotatedMixin(IMixinAnnotationProcessor ap, TypeElement type) { this.annotation = this.handle.getAnnotation(Mixin.class); this.classRef = TypeUtils.getInternalName(type); this.primaryTarget = this.initTargets(ap); - this.remap = this.annotation.getBoolean("remap", true) && this.targets.size() > 0; + this.remap = this.annotation.getBoolean("remap", true) && !this.targets.isEmpty(); this.overwrites = new AnnotatedMixinElementHandlerOverwrite(ap, this); this.shadows = new AnnotatedMixinElementHandlerShadow(ap, this); diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java index 2e7c7415f..f3cdcaae6 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java @@ -212,7 +212,7 @@ public boolean isCaseSensitive() { * Get whether this member has any aliases defined */ public boolean hasAliases() { - return this.aliases.size() > 0; + return !this.aliases.isEmpty(); } /** diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java index 5865fd569..032119df5 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationType.java @@ -120,7 +120,7 @@ public boolean isDefault() { * Get whether this obfuscation type has data available */ public boolean isSupported() { - return this.getInputFileNames().size() > 0; + return !this.getInputFileNames().isEmpty(); } /** diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/mapping/fg3/MappingProviderTSrg.java b/src/ap/java/org/spongepowered/tools/obfuscation/mapping/fg3/MappingProviderTSrg.java index 2ebd14a2f..f6dfd6c73 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/mapping/fg3/MappingProviderTSrg.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/mapping/fg3/MappingProviderTSrg.java @@ -47,7 +47,7 @@ */ public class MappingProviderTSrg extends MappingProvider { - private List inputMappings = new ArrayList(); + private final List inputMappings = new ArrayList(); public MappingProviderTSrg(Messager messager, Filer filer) { super(messager, filer); diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/mirror/TypeHandle.java b/src/ap/java/org/spongepowered/tools/obfuscation/mirror/TypeHandle.java index 5c2f1e6ac..887c77b6e 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/mirror/TypeHandle.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/mirror/TypeHandle.java @@ -475,7 +475,7 @@ protected static boolean compareElement(Element elem, String name, String type, String elementType = TypeUtils.getJavaSignature(elem); String rawElementType = TypeUtils.stripGenerics(elementType); boolean compared = matchCase ? name.equals(elementName) : name.equalsIgnoreCase(elementName); - return compared && (type.length() == 0 || type.equals(elementType) || type.equals(rawElementType)); + return compared && (type.isEmpty() || type.equals(elementType) || type.equals(rawElementType)); } catch (NullPointerException ex) { return false; } diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java b/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java index 72056c023..a57765e24 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/service/ObfuscationServices.java @@ -132,7 +132,7 @@ public void initProviders(IMixinAnnotationProcessor ap) { serviceError.printStackTrace(); } - if (supportedTypes.size() > 0) { + if (!supportedTypes.isEmpty()) { StringBuilder sb = new StringBuilder("Supported obfuscation types:"); for (Entry> supportedType : supportedTypes.entrySet()) { sb.append(' ').append(supportedType.getKey()).append(" supports [").append(Joiner.on(',').join(supportedType.getValue())).append(']'); diff --git a/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LaunchClassLoaderUtil.java b/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LaunchClassLoaderUtil.java index 0d7794833..e4a081835 100644 --- a/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LaunchClassLoaderUtil.java +++ b/src/launchwrapper/java/org/spongepowered/asm/service/mojang/LaunchClassLoaderUtil.java @@ -100,7 +100,7 @@ public String getClassRestrictions(String className) { restrictions = "PACKAGE_CLASSLOADER_EXCLUSION"; } if (this.isClassTransformerExcluded(className, null)) { - restrictions = (restrictions.length() > 0 ? restrictions + "," : "") + "PACKAGE_TRANSFORMER_EXCLUSION"; + restrictions = (!restrictions.isEmpty() ? restrictions + "," : "") + "PACKAGE_TRANSFORMER_EXCLUSION"; } return restrictions; } diff --git a/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java b/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java index a285024dc..c0ed77f15 100644 --- a/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java +++ b/src/main/java/org/spongepowered/asm/launch/platform/MixinContainer.java @@ -46,9 +46,7 @@ public class MixinContainer { static { GlobalProperties.put(GlobalProperties.Keys.AGENTS, MixinContainer.agentClasses); - for (String agent : MixinService.getService().getPlatformAgents()) { - MixinContainer.agentClasses.add(agent); - } + MixinContainer.agentClasses.addAll(MixinService.getService().getPlatformAgents()); MixinContainer.agentClasses.add("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault"); } diff --git a/src/main/java/org/spongepowered/asm/logging/LoggerAdapterAbstract.java b/src/main/java/org/spongepowered/asm/logging/LoggerAdapterAbstract.java index 496a60e07..07c454a7f 100644 --- a/src/main/java/org/spongepowered/asm/logging/LoggerAdapterAbstract.java +++ b/src/main/java/org/spongepowered/asm/logging/LoggerAdapterAbstract.java @@ -43,7 +43,7 @@ public abstract class LoggerAdapterAbstract implements ILogger { */ public static class FormattedMessage { - private String message; + private final String message; private Throwable t; @@ -65,7 +65,7 @@ public FormattedMessage(String message, Object... params) { if (delimPos < 0) { break; } - sb.append(message.substring(pos, delimPos)).append(params[param]); + sb.append(message, pos, delimPos).append(params[param]); pos = delimPos + 2; } if (pos < message.length()) { diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DynamicSelectorDesc.java b/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DynamicSelectorDesc.java index a13158505..bf9e0d788 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DynamicSelectorDesc.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/selectors/dynamic/DynamicSelectorDesc.java @@ -282,7 +282,7 @@ protected DynamicSelectorDesc(InvalidSelectorException ex, String id, Type owner public static DynamicSelectorDesc parse(String input, ISelectorContext context) { IResolvedDescriptor descriptor = DescriptorResolver.resolve(input, context); if (!descriptor.isResolved()) { - String extra = input.length() == 0 ? ". " + descriptor.getResolutionInfo() : ""; + String extra = input.isEmpty() ? ". " + descriptor.getResolutionInfo() : ""; return new DynamicSelectorDesc(new InvalidSelectorException("Could not resolve @Desc(" + input + ") for " + context + extra)); } return DynamicSelectorDesc.of(descriptor); diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java index bf6be2c55..9b279ab13 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java @@ -338,7 +338,7 @@ protected void parseSelectors() { TargetSelector.parse(Annotations.getValue(this.annotation, "target", false), this, selectors); // Raise an error if we have no selectors - if (selectors.size() == 0) { + if (selectors.isEmpty()) { throw new InvalidInjectionException(this, String.format("%s annotation on %s is missing 'method' or 'target' to specify targets", this.annotationType, this.methodName)); } @@ -406,7 +406,7 @@ protected void parseRequirements() { * @return true if this InjectionInfo was successfully parsed */ public boolean isValid() { - return this.targets.size() > 0 && this.injectionPoints.size() > 0; + return !this.targets.isEmpty() && !this.injectionPoints.isEmpty(); } /** @@ -451,9 +451,7 @@ public void inject() { * Perform cleanup and post-injection tasks */ public void postInject() { - for (MethodNode method : this.injectedMethods) { - this.classNode.methods.add(method); - } + this.classNode.methods.addAll(this.injectedMethods); String description = this.getDescription(); String refMapStatus = this.mixin.getReferenceMapper().getStatus(); @@ -686,7 +684,7 @@ protected String getDynamicInfo() { if (upstream != null) { description = String.format("{%s} %s", upstream.getClassName(), description).trim(); } - return description.length() > 0 ? String.format(" Method is @Dynamic(%s).", description) : ""; + return !description.isEmpty() ? String.format(" Method is @Dynamic(%s).", description) : ""; } /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectorGroupInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectorGroupInfo.java index ac1281294..dd760c6ac 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectorGroupInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectorGroupInfo.java @@ -251,7 +251,7 @@ public InjectorGroupInfo add(InjectionInfo member) { * @throws InjectionValidationException if validation fails */ public InjectorGroupInfo validate() throws InjectionValidationException { - if (this.members.size() == 0) { + if (this.members.isEmpty()) { // I have no idea how we got here, but it's not an error :/ return this; } diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java index dcbdecf00..61f23026f 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java @@ -928,13 +928,13 @@ public static MemberInfo parse(final String input, final ISelectorContext contex int bracePos = name.indexOf("{"); if (bracePos >= 0) { try { - quantifier = Quantifier.parse(name.substring(bracePos, name.length())); + quantifier = Quantifier.parse(name.substring(bracePos)); name = name.substring(0, bracePos); } catch (Exception ex) { // Handled later in validate since matchCount will be 0 } } - } else if (name.indexOf("{") >= 0) { + } else if (name.contains("{")) { quantifier = Quantifier.NONE; // Probably incomplete quantifier } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java index 27cef3057..45bb4ee28 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java @@ -784,7 +784,7 @@ protected void applyInitialisers(MixinTargetContext mixin) { // Find the initialiser instructions in the candidate ctor Deque initialiser = this.getInitialiser(mixin, ctor); - if (initialiser == null || initialiser.size() == 0) { + if (initialiser == null || initialiser.isEmpty()) { return; } @@ -970,14 +970,14 @@ protected final void injectInitialiser(MixinTargetContext mixin, MethodNode ctor } for (AbstractInsnNode node : initialiser) { - if (node instanceof LabelNode) { + //if (node instanceof LabelNode) { // Fabric: Merge cloned labels instead of skipping them. // continue; - } - if (node instanceof JumpInsnNode) { + //} + //if (node instanceof JumpInsnNode) { // Fabric: Jumps cause no issues if labels are cloned properly and should not be needlessly restricted. // throw new InvalidMixinException(mixin, "Unsupported JUMP opcode in initialiser in " + mixin); - } + //} AbstractInsnNode imACloneNow = node.clone(labels); ctor.instructions.insert(insn, imACloneNow); insn = imACloneNow; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java index 351409f61..d7ab71983 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java @@ -832,7 +832,7 @@ private void prepareMixins(String collectionName, List mixinClasses, boo } if (Strings.isNullOrEmpty(this.mixinPackage)) { - if (mixinClasses.size() > 0) { + if (!mixinClasses.isEmpty()) { this.logger.error("{} declares mixin classes in {} but does not specify a package, {} orphaned mixins will not be loaded: {}", this, collectionName, mixinClasses.size(), mixinClasses); } @@ -867,7 +867,7 @@ private void prepareMixins(String collectionName, List mixinClasses, boo for (MixinInfo mixin : this.pendingMixins) { try { mixin.parseTargets(); - if (mixin.getTargetClasses().size() > 0) { + if (!mixin.getTargetClasses().isEmpty()) { for (String targetClass : mixin.getTargetClasses()) { String targetClassName = targetClass.replace('/', '.'); this.mixinsFor(targetClassName).add(mixin); diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java index 24eafa86d..18cbfbd90 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -1305,7 +1305,7 @@ private ClassNode loadMixinClass(String mixinClassName) throws ClassNotFoundExce IClassTracker tracker = this.service.getClassTracker(); if (tracker != null) { String restrictions = tracker.getClassRestrictions(mixinClassName); - if (restrictions.length() > 0) { + if (!restrictions.isEmpty()) { this.logger.error("Classloader restrictions [{}] encountered loading {}, name: {}", restrictions, this, mixinClassName); } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java index d6fcac4ba..c34a89007 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java @@ -839,7 +839,7 @@ private static String getDynamicInfo(String targetType, AnnotationNode annotatio if (upstream != null) { description = String.format("{%s} %s", upstream.getClassName(), description).trim(); } - return description.length() > 0 ? String.format(" %s is @Dynamic(%s)", targetType, description) : ""; + return !description.isEmpty() ? String.format(" %s is @Dynamic(%s)", targetType, description) : ""; } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java index 2ff0862a4..2b6b58837 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java @@ -899,7 +899,7 @@ private void updateBinding(MethodNode method, MemberRef methodRef, Traversal tra * @param field Field node to transform */ void transformDescriptor(FieldNode field) { - if (!this.inheritsFromMixin && this.innerClasses.size() == 0) { + if (!this.inheritsFromMixin && this.innerClasses.isEmpty()) { return; } field.desc = this.transformSingleDescriptor(field.desc, false); @@ -911,7 +911,7 @@ void transformDescriptor(FieldNode field) { * @param method Method node to transform */ void transformDescriptor(MethodNode method) { - if (!this.inheritsFromMixin && this.innerClasses.size() == 0) { + if (!this.inheritsFromMixin && this.innerClasses.isEmpty()) { return; } method.desc = this.transformMethodDescriptor(method.desc); @@ -924,7 +924,7 @@ void transformDescriptor(MethodNode method) { * @param member Reference to the method or field */ void transformDescriptor(MemberRef member) { - if (!this.inheritsFromMixin && this.innerClasses.size() == 0) { + if (!this.inheritsFromMixin && this.innerClasses.isEmpty()) { return; } if (member.isField()) { @@ -940,7 +940,7 @@ void transformDescriptor(MemberRef member) { * @param typeInsn Type instruction node to transform */ void transformDescriptor(TypeInsnNode typeInsn) { - if (!this.inheritsFromMixin && this.innerClasses.size() == 0) { + if (!this.inheritsFromMixin && this.innerClasses.isEmpty()) { return; } typeInsn.desc = this.transformSingleDescriptor(typeInsn.desc, true); diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/Extensions.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/Extensions.java index 8512cfbae..82586c846 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/Extensions.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/Extensions.java @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; @@ -52,7 +52,7 @@ public final class Extensions implements IExtensionRegistry { * generators using {@link #getExtension} */ private final Map, IExtension> extensionMap - = new HashMap, IExtension>(); + = new IdentityHashMap, IExtension>(); /** * Modules which generate synthetic classes required by mixins @@ -69,7 +69,7 @@ public final class Extensions implements IExtensionRegistry { * generators using {@link #getGenerator} */ private final Map, IClassGenerator> generatorMap - = new HashMap, IClassGenerator>(); + = new IdentityHashMap, IClassGenerator>(); private final ISyntheticClassRegistry syntheticClassRegistry; diff --git a/src/main/java/org/spongepowered/asm/service/MixinServiceAbstract.java b/src/main/java/org/spongepowered/asm/service/MixinServiceAbstract.java index c01c814d7..d25ad65e8 100644 --- a/src/main/java/org/spongepowered/asm/service/MixinServiceAbstract.java +++ b/src/main/java/org/spongepowered/asm/service/MixinServiceAbstract.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; @@ -74,7 +75,7 @@ public abstract class MixinServiceAbstract implements IMixinService { /** * All internals offered to this service */ - private final Map, IMixinInternal> internals = new HashMap, IMixinInternal>(); + private final Map, IMixinInternal> internals = new IdentityHashMap, IMixinInternal>(); /** * Service agent instances diff --git a/src/main/java/org/spongepowered/asm/util/ClassSignature.java b/src/main/java/org/spongepowered/asm/util/ClassSignature.java index 6b9033a07..af8ecb3a5 100644 --- a/src/main/java/org/spongepowered/asm/util/ClassSignature.java +++ b/src/main/java/org/spongepowered/asm/util/ClassSignature.java @@ -1264,13 +1264,13 @@ public SignatureVisitor getRemapper() { */ @Override public String toString() { - while (this.rawInterfaces.size() > 0) { + while (!this.rawInterfaces.isEmpty()) { this.addRawInterface(this.rawInterfaces.remove()); } StringBuilder sb = new StringBuilder(); - if (this.types.size() > 0) { + if (!this.types.isEmpty()) { boolean valid = false; StringBuilder types = new StringBuilder(); for (Entry type : this.types.entrySet()) { diff --git a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java index 0479dc67d..b03313106 100644 --- a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java +++ b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java @@ -283,7 +283,7 @@ private ConstraintParser() { * @return parsed constraint */ public static Constraint parse(String expr) { - if (expr == null || expr.length() == 0) { + if (expr == null || expr.isEmpty()) { return Constraint.NONE; } diff --git a/src/main/java/org/spongepowered/asm/util/LanguageFeatures.java b/src/main/java/org/spongepowered/asm/util/LanguageFeatures.java index 4044d8652..918be4234 100644 --- a/src/main/java/org/spongepowered/asm/util/LanguageFeatures.java +++ b/src/main/java/org/spongepowered/asm/util/LanguageFeatures.java @@ -116,7 +116,7 @@ private static int scanClassFeatures(ClassNode classNode) { String nestHostClass = ClassNodeAdapter.getNestHostClass(classNode); List nestMembers = ClassNodeAdapter.getNestMembers(classNode); - if (nestHostClass != null || (nestMembers != null && nestMembers.size() > 0)) { + if (nestHostClass != null || (nestMembers != null && !nestMembers.isEmpty())) { features |= LanguageFeatures.NESTING; } diff --git a/src/main/java/org/spongepowered/asm/util/Quantifier.java b/src/main/java/org/spongepowered/asm/util/Quantifier.java index 12141ec75..7ab6fa6f8 100644 --- a/src/main/java/org/spongepowered/asm/util/Quantifier.java +++ b/src/main/java/org/spongepowered/asm/util/Quantifier.java @@ -146,7 +146,7 @@ public String toString() { * @return parsed quantifier, malformed quantifiers return NONE */ public static Quantifier parse(String string) { - if (string == null || ((string = string.trim()).length() == 0)) { + if (string == null || ((string = string.trim()).isEmpty())) { return Quantifier.DEFAULT; } @@ -177,8 +177,8 @@ public static Quantifier parse(String string) { } try { - int min = strMin.length() > 0 ? Integer.parseInt(strMin) : 0; - int max = strMax.length() > 0 ? Integer.parseInt(strMax) : Integer.MAX_VALUE; + int min = !strMin.isEmpty() ? Integer.parseInt(strMin) : 0; + int max = !strMax.isEmpty() ? Integer.parseInt(strMax) : Integer.MAX_VALUE; return new Quantifier(min, max); } catch (NumberFormatException ex) { return Quantifier.NONE; diff --git a/src/main/java/org/spongepowered/asm/util/perf/Profiler.java b/src/main/java/org/spongepowered/asm/util/perf/Profiler.java index cf2e6d446..c1e4b2ebe 100644 --- a/src/main/java/org/spongepowered/asm/util/perf/Profiler.java +++ b/src/main/java/org/spongepowered/asm/util/perf/Profiler.java @@ -1029,9 +1029,7 @@ public Section get(Object name) { } }; for (Profiler profiler : Profiler.profilers.values()) { - for (String phase : profiler.phases) { - allPhases.add(phase); - } + allPhases.addAll(profiler.phases); for (Entry section : profiler.sections.entrySet()) { ((ResultSection)allSections.get(section.getKey())).add(section.getValue()); diff --git a/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java b/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java index 56774262b..e5842adc8 100644 --- a/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java +++ b/src/modlauncher/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncher.java @@ -40,8 +40,8 @@ public class ContainerHandleModLauncher extends ContainerHandleVirtual { */ class Resource extends ContainerHandleURI { - private String name; - private Path path; + private final String name; + private final Path path; public Resource(String name, Path path) { super(path.toUri()); diff --git a/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java b/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java index a6553ef5d..18f6f67d8 100644 --- a/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java +++ b/src/modlauncher9/java/org/spongepowered/asm/launch/platform/container/ContainerHandleModLauncherEx.java @@ -38,7 +38,7 @@ public class ContainerHandleModLauncherEx extends ContainerHandleModLauncher { */ static class SecureJarResource extends ContainerHandleURI { - private SecureJar jar; + private final SecureJar jar; public SecureJarResource(SecureJar resource) { super(resource.getPrimaryPath().toUri());