Optimize comparator check for sortedIndex