Optimize comparisons such that compareTo() is invoked only once