Apply sorted patterns as ranges instead of row-by-row.

This scrapes off additional 2.2 seconds.

Change-Id: I08ae67f45946721d722be7183270d7bcf01f96b0