Small optimizations to stencil scanning.