Mercurial > vim
changeset 13804:8a35543f5f97 v8.0.1774
patch 8.0.1774: reading very long lines can be slow
commit https://github.com/vim/vim/commit/13d3b05ed2cf9a54b18b4e8236f0af2c5386200c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 29 13:34:47 2018 +0200
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 29 Apr 2018 13:45:04 +0200 |
parents | d93f2231a72d |
children | 09f997645d11 |
files | src/fileio.c src/version.c |
diffstat | 2 files changed, 28 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fileio.c +++ b/src/fileio.c @@ -1209,28 +1209,42 @@ retry: * The amount is limited by the fact that read() only can read * upto max_unsigned characters (and other things). */ + if (!skip_read) + { +#if VIM_SIZEOF_INT > 2 +# if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L) + size = SSIZE_MAX; /* use max I/O size, 52K */ +# else + /* 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; +# endif +#else + size = 0x7ff0L - linerest; /* limit buffer to 32K */ +#endif + } + + /* Protect against the argument of lalloc() going negative. */ + if ( #if VIM_SIZEOF_INT <= 2 - if (linerest >= 0x7ff0) + linerest >= 0x7ff0 +#else + size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL +#endif + ) { ++split; *ptr = NL; /* split line by inserting a NL */ size = 1; } else -#endif { if (!skip_read) { -#if VIM_SIZEOF_INT > 2 -# if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L) - size = SSIZE_MAX; /* use max I/O size, 52K */ -# else - size = 0x10000L; /* use buffer >= 64K */ -# endif -#else - size = 0x7ff0L - linerest; /* limit buffer to 32K */ -#endif - for ( ; size >= 10; size = (long)((long_u)size >> 1)) { if ((new_buffer = lalloc((long_u)(size + linerest + 1),