]> git.lyx.org Git - lyx.git/commitdiff
In the no-draw phase, do not cache the positions of not visible insets
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 24 Jul 2023 15:53:16 +0000 (17:53 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Apr 2024 14:45:58 +0000 (16:45 +0200)
This can make a big difference for a very large branch that contains
lots of equations.

This is complementary to the previous patch, since instead of reducing
the number of calls to updatePosCache, we make it faster.

In the same test of scrolling with mouse wheel through the
branch-test.lyx document, one finds a 23% improvement for
BufferView::updateMetrics().

Part of bug #12297.

(cherry picked from commit 7f85024f80601b15634fb5e771bba51435ad429f)

src/TextMetrics.cpp

index 6968279c239d01df0f2afa09c09978f151b72f42..06e00f42201c90de2dfd876af30370a7ce2cdd0d 100644 (file)
@@ -2000,6 +2000,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
        if (pm.rows().empty())
                return;
        size_t const nrows = pm.rows().size();
+       int const wh = bv_->workHeight();
        // Remember left and right margin for drawing math numbers
        Changer changeleft = changeVar(pi.leftx, x + leftMargin(pit));
        Changer changeright = changeVar(pi.rightx, x + width() - rightMargin(pit));
@@ -2014,15 +2015,17 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                        if (i)
                                y += row.ascent();
 
-                       RowPainter rp(pi, *text_, row, row_x, y);
-
-                       rp.paintOnlyInsets();
+                       // It is not needed to draw on screen if we are not inside
+                       bool const inside = (y + row.descent() >= 0 && y - row.ascent() < wh);
+                       if (inside) {
+                               RowPainter rp(pi, *text_, row, row_x, y);
+                               rp.paintOnlyInsets();
+                       }
                        y += row.descent();
                }
                return;
        }
 
-       int const ww = bv_->workHeight();
        Cursor const & cur = bv_->cursor();
        DocIterator sel_beg = cur.selectionBegin();
        DocIterator sel_end = cur.selectionEnd();
@@ -2065,7 +2068,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
 
                // It is not needed to draw on screen if we are not inside.
                bool const inside = (y + row.descent() >= 0
-                       && y - row.ascent() < ww);
+                       && y - row.ascent() < wh);
                if (!inside) {
                        // Inset positions have already been set in nodraw stage.
                        y += row.descent();