Simplify comparisons for small unsigned types that can fit in Int

UByte and UShort can be extended to Int exactly and then compared as ints
This commit is contained in:
Ilya Gorbunov
2018-09-18 17:57:18 +03:00
parent af29dced98
commit 1d7ee22bdc
3 changed files with 10 additions and 6 deletions
+6 -2
View File
@@ -109,8 +109,12 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) {
out.println("${className.toLowerCase()}Compare(this.data, other.data)")
} else {
val ctype = maxByDomainCapacity(maxByDomainCapacity(type, otherType), UnsignedType.UINT)
out.println("${convert("this", type, ctype)}.compareTo(${convert("other", otherType, ctype)})")
if (maxOf(type, otherType) < UnsignedType.UINT) {
out.println("this.toInt().compareTo(other.toInt())")
} else {
val ctype = maxByDomainCapacity(type, otherType)
out.println("${convert("this", type, ctype)}.compareTo(${convert("other", otherType, ctype)})")
}
}
}
out.println()