Small optimization in erode function with ~5x performance gain.