merge bug25939 into bug25943
lift buffer vars from state

This improves performance by reducing state update and also makes it
clear that these vars are only updated in the two loop functions.
cosmetic
Merge bug 25943