diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-06 12:04:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-06 12:04:24 +0800 |
commit | f4df49a9598151343af3fc4a30b8a42608c52bb6 (patch) | |
tree | 10a7f6970fa29c08d3ae16b425ee04af308e461b | |
parent | ae28ef327e02ac87ef26f941c401312ed0462d8c (diff) | |
download | rneovim-f4df49a9598151343af3fc4a30b8a42608c52bb6.tar.gz rneovim-f4df49a9598151343af3fc4a30b8a42608c52bb6.tar.bz2 rneovim-f4df49a9598151343af3fc4a30b8a42608c52bb6.zip |
revert: "vim-patch:9.1.0055: formatting long lines is slow"
Revert "vim-patch:9.1.0055: formatting long lines is slow (#27199)"
This reverts commit 89a9745a1a55dc9ffd0f8292735e45bae6c7b01e.
Fix #28197
-rw-r--r-- | src/nvim/textformat.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index c427206764..1722bcc968 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -105,14 +105,9 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on colnr_T col; bool did_do_comment = false; - // Cursor is currently at the end of line. No need to format - // if line length is less than textwidth (8 * textwidth for - // utf safety) - if (curwin->w_cursor.col < 8 * textwidth) { - colnr_T virtcol = get_nolist_virtcol() + char2cells(c != NUL ? c : gchar_cursor()); - if (virtcol <= (colnr_T)textwidth) { - break; - } + colnr_T virtcol = get_nolist_virtcol() + char2cells(c != NUL ? c : gchar_cursor()); + if (virtcol <= (colnr_T)textwidth) { + break; } if (no_leader) { @@ -160,16 +155,9 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on coladvance(curwin, (colnr_T)textwidth); wantcol = curwin->w_cursor.col; - // If startcol is large (a long line), formatting takes too much - // time. The algorithm is O(n^2), it walks from the end of the - // line to textwidth border every time for each line break. - // - // Ceil to 8 * textwidth to optimize. - curwin->w_cursor.col = startcol < 8 * textwidth ? startcol : 8 * textwidth; - + curwin->w_cursor.col = startcol; foundcol = 0; int skip_pos = 0; - bool first_pass = true; // Find position to break at. // Stop at first entered white when 'formatoptions' has 'v' @@ -177,9 +165,8 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on || (flags & INSCHAR_FORMAT) || curwin->w_cursor.lnum != Insstart.lnum || curwin->w_cursor.col >= Insstart.col) { - if (first_pass && c != NUL) { + if (curwin->w_cursor.col == startcol && c != NUL) { cc = c; - first_pass = false; } else { cc = gchar_cursor(); } |