hash_equals: Add optimizations inspired from CPython