This is much faster than appending one line at a time. BUG: 442739 (cherry picked from commit ec3989ff)