Optimize equality check