commit e5bb491e2e10a8097284d11eae5501a3673731cb
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Fri Oct 8 17:38:25 2021 +0200

    Reduce the number of accesses to coord cache when drawing a math row
    
    Each of these accesses is somewhat costly when using large branches
    with lots of maths
    
    Related to bug #12297.
---
 src/CoordCache.h       |    6 ++++++
 src/mathed/MathRow.cpp |   16 +++++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/CoordCache.h b/src/CoordCache.h
index 2780fc3..44ac26c 100644
--- a/src/CoordCache.h
+++ b/src/CoordCache.h
@@ -80,6 +80,12 @@ public:
                data_[thing].dim = dim;
        }
 
+       Geometry & geometry(T const * thing)
+       {
+               check(thing, "geometry");
+               return data_.find(thing)->second;
+       }
+
        Geometry const & geometry(T const * thing) const
        {
                check(thing, "geometry");
diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index b8a9a95..81b6ad9 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -322,18 +322,16 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
                        // This is hackish: the math inset does not know that 
space
                        // has been added before and after it; we alter its 
dimension
                        // while it is drawing, because it relies on this value.
-                       Dimension const d = coords.insets().dim(e.inset);
-                       Dimension d2 = d;
-                       d2.wid -= e.before + e.after;
-                       coords.insets().add(e.inset, d2);
+                       Geometry & g = coords.insets().geometry(e.inset);
+                       g.dim.wid -= e.before + e.after;
                        if (pi.pain.develMode() && !e.inset->isBufferValid())
-                               pi.pain.fillRectangle(x + e.before, y - 
d2.ascent(),
-                                                     d2.width(), d2.height(), 
Color_error);
+                               pi.pain.fillRectangle(x + e.before, y - 
g.dim.ascent(),
+                                                     g.dim.width(), 
g.dim.height(), Color_error);
                        e.inset->draw(pi, x + e.before, y);
-                       coords.insets().add(e.inset, x, y);
-                       coords.insets().add(e.inset, d);
+                       g.pos = {x, y};
+                       g.dim.wid += e.before + e.after;
                        drawMarkers(pi, e, x, y);
-                       x += d.wid;
+                       x += g.dim.wid;
                        break;
                }
                case BEGIN:
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to