diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java index c236865..939ccaf 100644 --- a/src/org/ice4j/ice/CandidatePair.java +++ b/src/org/ice4j/ice/CandidatePair.java @@ -24,6 +24,12 @@ import org.ice4j.stack.*; public class CandidatePair implements Comparable { + /** + * The value of Math.pow(2, 32) calculated once for the purposes of + * optimizing performance. + */ + private static final long MATH_POW_2_32 = 1L << 32; + /** * The local candidate of this pair. */ @@ -337,14 +343,26 @@ public class CandidatePair */ protected void computePriority() { - //use G and D as local and remote candidate priority names to fit the - //definition in the RFC. - long G = getControllingAgentCandidate().getPriority(); - long D = getControlledAgentCandidate().getPriority(); + // Use g and d as local and remote candidate priority names to fit the + // definition in the RFC. + long g = getControllingAgentCandidate().getPriority(); + long d = getControlledAgentCandidate().getPriority(); + long min, max, expr; - this.priority = (long)Math.pow(2, 32)*Math.min(G,D) - + 2*Math.max(G,D) - + (G>D?1l:0l); + if (g > d) + { + min = d; + max = g; + expr = 1L; + } + else + { + min = g; + max = d; + expr = 0L; + } + + this.priority = MATH_POW_2_32 * min + 2 * max + expr; } /**