From: Gregory Heytings Date: Sat, 1 Apr 2023 14:14:45 +0000 (+0000) Subject: Improve and fix last changes X-Git-Tag: emacs-29.0.91~11^2~5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dce08cf05ccd2551d2e304e868605102233f8c40;p=emacs.git Improve and fix last changes * src/xdisp.c (get_narrowed_width): Use WINDOW_RIGHT_FRINGE_WIDTH, which works both for character-only terminals and for GUI frames without fringes. (get_nearby_bol_pos): Instead of searching for BOL in [pos-500000..pos], gradually extend the region, starting with [pos-500..pos]. This is much faster in buffers with some long lines in the middle of lots of short lines. --- diff --git a/src/xdisp.c b/src/xdisp.c index 880d1b0f1fa..438cbac1274 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3580,14 +3580,14 @@ init_iterator (struct it *it, struct window *w, static int get_narrowed_width (struct window *w) { - bool term = EQ (Fterminal_live_p (Qnil), Qt); /* In a character-only terminal, only one font size is used, so we can use a smaller factor. */ - int fact = term ? 2 : 3; - /* In a character-only terminal, subtract 1 from the width for the + int fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3; + /* If the window has no fringes (in a character-only terminal or in + a GUI frame without fringes), subtract 1 from the width for the '\' line wrapping character. */ int width = window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) - - (term ? 1 : 0); + - (WINDOW_RIGHT_FRINGE_WIDTH (w) == 0 ? 1 : 0); return fact * max (1, width); } @@ -3616,16 +3616,25 @@ static ptrdiff_t get_nearby_bol_pos (ptrdiff_t pos) { ptrdiff_t start, pos_bytepos, cur, next, found, bol = 0; - start = pos - 500000 < BEGV ? BEGV : pos - 500000; - pos_bytepos = CHAR_TO_BYTE (pos); - for (cur = start; cur < pos; cur = next) + int dist; + for (dist = 500; dist <= 500000; dist *= 10) { - next = find_newline1 (cur, CHAR_TO_BYTE (cur), pos, pos_bytepos, - 1, &found, NULL, false); - if (found) - bol = next; + pos_bytepos = pos == BEGV ? BEGV_BYTE : CHAR_TO_BYTE (pos); + start = pos - dist < BEGV ? BEGV : pos - dist; + for (cur = start; cur < pos; cur = next) + { + next = find_newline1 (cur, CHAR_TO_BYTE (cur), + pos, pos_bytepos, + 1, &found, NULL, false); + if (found) + bol = next; + else + break; + } + if (bol) + return bol; else - break; + pos = pos - dist < BEGV ? BEGV : pos - dist; } return bol; }