Fix #1035: StackOverflowError on save

by performing the easy and cheap check first.

I’m not sure if it makes sense that this fixes the bug, but it no longer happens for me, and anyway the change makes sense to me :)