Avoid iterating over records hash when not necessary

If the reflection scope is not flagged with distinct value, there is no
need to iterate over the records, so we avoid that by doing the check
before iterating rather than inside the iteration block.