Avoid expensive for..in loops involving CMaps

This is much the same as #4804, which was abandoned.
What's wrong with the `in` operator?