vim-patch:8.0.1774: reading very long lines can be slow

Problem:    Reading very long lines can be slow.
Solution:   Read up to 1 Mbyte at a time to avoid a lot of copying.  Add a
            check for going over the column limit.
13d3b05ed2
This commit is contained in:
Jan Edmund Lazo 2020-07-17 06:30:23 -04:00
parent 55ff49b1a7
commit 521d571992
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -300,6 +300,7 @@ readfile(
int skip_read = false;
context_sha256_T sha_ctx;
int read_undo_file = false;
int split = 0; // number of split lines
linenr_T linecnt;
int error = FALSE; /* errors encountered */
int ff_error = EOL_UNKNOWN; /* file format with errors */
@ -1013,8 +1014,21 @@ retry:
*/
{
if (!skip_read) {
size = 0x10000L; /* use buffer >= 64K */
// Use buffer >= 64K. Add linerest to double the size if the
// line gets very long, to avoid a lot of copying. But don't
// read more than 1 Mbyte at a time, so we can be interrupted.
size = 0x10000L + linerest;
if (size > 0x100000L) {
size = 0x100000L;
}
}
// Protect against the argument of lalloc() going negative.
if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL) {
split++;
*ptr = NL; // split line by inserting a NL
size = 1;
} else if (!skip_read) {
for (; size >= 10; size /= 2) {
new_buffer = verbose_try_malloc((size_t)size + (size_t)linerest + 1);
if (new_buffer) {
@ -1862,6 +1876,10 @@ failed:
STRCAT(IObuff, _("[CR missing]"));
c = TRUE;
}
if (split) {
STRCAT(IObuff, _("[long lines split]"));
c = true;
}
if (notconverted) {
STRCAT(IObuff, _("[NOT converted]"));
c = TRUE;