Improve performance when processing files with few newlines