Optimization of compoundCompare()