Subject: Re: bug#56682: Fix the long lines font locking related slowdowns

From: Gregory Heytings <[email-masked]>
Date: Fri, 29 Jul 2022 20:02:47 +0000

>
> Doing it in init_iterator is too early alas, with the above recipe at 
> least init_iterator is called with charpos inside the narrowing bounds, 
> after which the iterator moves outside the narrowing bounds.  So I fixed 
> the bug in handle_fontified_prop.
>

Actually that doesn't work correctly.  A recipe:

emacs -Q
M-: (progn (set-frame-width nil 119) (set-frame-height nil 38)) RET
C-x C-f dictionary.json RET y
C-s aan SPC

Now you'll see that the last line at the bottom of the window, which does 
not contain "aan ", is highlighted.  Is the following okay from your point 
of view?

diff --git a/src/xdisp.c b/src/xdisp.c
index b1ee7889d4..8c62f088b8 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -4412,13 +4412,8 @@ handle_fontified_prop (struct it *it)
           ptrdiff_t begv = it->narrowed_begv ? it->narrowed_begv : BEGV;
           ptrdiff_t zv = it->narrowed_zv;
           ptrdiff_t charpos = IT_CHARPOS (*it);
-         if (charpos < begv || charpos > zv)
-           {
-             begv = get_narrowed_begv (it->w, charpos);
-             if (!begv) begv = BEGV;
-             zv = get_narrowed_zv (it->w, charpos);
-           }
-         Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt);
+         if (begv <= charpos && charpos <= zv)
+           Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt);
         }

        /* Don't allow Lisp that runs from 'fontification-functions'