Cherry-pick commit 15171 from trunk (#6529: further optimize consistency check).

git-svn-id: http://caml.inria.fr/svn/ocaml/version/4.02@15172 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02