That will indeed be horribly inefficient. But, in nontrivial cases, the
whole plan of hash=0 for circular references is problematically inefficient
too. So this suggests reconsidering that whole idea in the algorithm.
This is the sort of thing I wanted your fresh brainpower on.
Consider a <pointer_type type=.../> DIE. There are zillions of those
All of those that are part of a circular reference chain hash as the same.
(See e.g. the --stats output on any C++ case, where there are these and
also zillions of the equivalent reference_type cases.)
So we wind up comparing against all those in the same hash bucket, which is
far from optimal. The best the current (buggy) plan gets is to do negative
caching of each individual comparison. But even if all that caching code
were perfectly correct, it stills winds up being n separate hash lookups
to do the n "quick" comparisons. So this is not really an adequate plan.