Merge 3.3 into default.

cwr_next():  move invariants out of loops.

This simplifies and clarifies the code, and gives a small speedup.