diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-07-17 06:30:23 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-08-02 12:00:00 -0400 |
commit | 521d571992e580f9b87449c5f19bc72818cbb8e1 (patch) | |
tree | 2e996a12825fbd072b9b5d2717c8132c10a38af6 /src | |
parent | 55ff49b1a79d557848cb9c156a913538a876ddc6 (diff) | |
download | rneovim-521d571992e580f9b87449c5f19bc72818cbb8e1.tar.gz rneovim-521d571992e580f9b87449c5f19bc72818cbb8e1.tar.bz2 rneovim-521d571992e580f9b87449c5f19bc72818cbb8e1.zip |
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.
https://github.com/vim/vim/commit/13d3b05ed2cf9a54b18b4e8236f0af2c5386200c
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/fileio.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 20f0cdccc3..f922591d0b 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -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; |