Optimized unique check.