replace a loop with a constant time check.