diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index 60718b81..16aaa2ee 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -49,6 +49,7 @@ import org.spongepowered.asm.service.IMixinService; import org.spongepowered.asm.service.ITransformer; import org.spongepowered.asm.service.MixinService; import org.spongepowered.asm.service.MixinServiceAbstract; +import org.spongepowered.asm.util.CompareUtil; import org.spongepowered.asm.util.Constants; import org.spongepowered.asm.util.IConsumer; import org.spongepowered.asm.util.ITokenProvider; @@ -812,13 +813,11 @@ public final class MixinEnvironment implements ITokenProvider { @Override public int compareTo(TokenProviderWrapper other) { - if (other == null) { - return 0; - } if (other.priority == this.priority) { - return other.order - this.order; + return CompareUtil.compare(other.order, this.order); + } else { + return (other.priority < this.priority) ? -1 : 1; } - return (other.priority - this.priority); } public IEnvironmentTokenProvider getProvider() { diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionNodes.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionNodes.java index 235d7f17..52c13081 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionNodes.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionNodes.java @@ -30,6 +30,7 @@ import java.util.Map; import org.objectweb.asm.tree.AbstractInsnNode; import org.spongepowered.asm.util.Bytecode; +import org.spongepowered.asm.util.CompareUtil; /** * Used to keep track of instruction nodes in a {@link Target} method which are @@ -197,7 +198,7 @@ public class InjectionNodes extends ArrayList { */ @Override public int compareTo(InjectionNode other) { - return other == null ? Integer.MAX_VALUE : this.hashCode() - other.hashCode(); + return other == null ? Integer.MAX_VALUE : CompareUtil.compare(this.hashCode(), other.hashCode()); } /* (non-Javadoc) 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 c608d293..9a84722d 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java @@ -52,6 +52,7 @@ import org.spongepowered.asm.mixin.refmap.RemappingReferenceMapper; import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.service.IMixinService; import org.spongepowered.asm.service.MixinService; +import org.spongepowered.asm.util.CompareUtil; import org.spongepowered.asm.util.VersionNumber; import com.google.common.base.Strings; @@ -1000,9 +1001,10 @@ final class MixinConfig implements Comparable, IMixinConfig { return 0; } if (other.priority == this.priority) { - return this.order - other.order; + return CompareUtil.compare(this.order, other.order); + } else { + return (this.priority < other.priority) ? -1 : 1; } - return (this.priority - other.priority); } /** 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 942e107d..8dd6bc82 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -67,6 +67,7 @@ import org.spongepowered.asm.service.IMixinService; import org.spongepowered.asm.service.MixinService; import org.spongepowered.asm.util.Annotations; import org.spongepowered.asm.util.Bytecode; +import org.spongepowered.asm.util.CompareUtil; import org.spongepowered.asm.util.perf.Profiler; import org.spongepowered.asm.util.perf.Profiler.Section; @@ -1200,9 +1201,10 @@ class MixinInfo implements Comparable, IMixinInfo { return 0; } if (other.priority == this.priority) { - return this.order - other.order; + return CompareUtil.compare(this.order, other.order); + } else { + return (this.priority < other.priority) ? -1 : 1; } - return (this.priority - other.priority); } /** diff --git a/src/main/java/org/spongepowered/asm/util/CompareUtil.java b/src/main/java/org/spongepowered/asm/util/CompareUtil.java new file mode 100644 index 00000000..7b1be4f9 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/util/CompareUtil.java @@ -0,0 +1,45 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.asm.util; + +/** + * Comparison helpers. + */ +public final class CompareUtil { + private CompareUtil() { + + } + + /** + * Officially added in Java 7. + */ + public static int compare(int a, int b) { + return ((a < b) ? -1 : ((a == b) ? 0 : 1)); + } + + public static int compare(long a, long b) { + return ((a < b) ? -1 : ((a == b) ? 0 : 1)); + } +} diff --git a/src/main/java/org/spongepowered/asm/util/VersionNumber.java b/src/main/java/org/spongepowered/asm/util/VersionNumber.java index 398e2ed3..9cd9e4e1 100644 --- a/src/main/java/org/spongepowered/asm/util/VersionNumber.java +++ b/src/main/java/org/spongepowered/asm/util/VersionNumber.java @@ -106,8 +106,7 @@ public final class VersionNumber implements Comparable, Serializa if (other == null) { return 1; } - long delta = this.value - other.value; - return delta > 0 ? 1 : delta < 0 ? -1 : 0; + return CompareUtil.compare(this.value, other.value); } /* (non-Javadoc)