Optimized equality check