Optimize check that constraints are satisfied

Seems to shave about 20% off of the gitlabhq test (25s -> 20s).