Skip to content

Commit 8105a4f

Browse files
Optimized compareTo for Number
1 parent 0c620e8 commit 8105a4f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/it/unipr/analysis/Number.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,16 @@ public String toString() {
302302

303303
@Override
304304
public int compareTo(Number other) {
305+
if (getType() == other.getType()) {
306+
if (getType() == Type.INT)
307+
return Integer.compare(this.i, other.i);
308+
else if (getType() == Type.LONG)
309+
return Long.compare(this.l, other.l);
310+
}
311+
312+
// Otherwise, fall back to BigInteger comparisons.
305313
BigInteger me = toBigInteger(this);
306314
BigInteger ot = toBigInteger(other);
307-
308315
return me.compareTo(ot);
309316
}
310317

0 commit comments

Comments
 (0)