commit e1e37161f331cb8f2af7d22d05c5910068d644ce
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Sat Jun 6 21:33:21 2026 +0200

    Cache the MathData version of macro definition
    
    Add a member definition_data_ to MathData to avoid having to convert
    the string definition over and over.
    
    Improves performance.
    
    Part of ticket #13321.
    
    (cherry picked from commit f043262c39126cccdea7e683345cddd0e9ef3962)
---
 src/mathed/InsetMathMacro.cpp | 7 ++-----
 src/mathed/MacroTable.cpp     | 7 ++++---
 src/mathed/MacroTable.h       | 8 ++++++--
 status.25x                    | 3 +++
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 43ddb3b084..e9ec10ce0b 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -988,11 +988,8 @@ void InsetMathMacro::validate(LaTeXFeatures & features) 
const
                if (displayMode() == DISPLAY_NORMAL)
                        d->definition_.validate(features);
                else if (displayMode() == DISPLAY_INIT) {
-                       if (MacroData const * data = buffer().getMacro(name())) 
{
-                               MathData md(const_cast<Buffer *>(&buffer()));
-                               asMathData(data->definition(), md);
-                               md.validate(features);
-                       }
+                       if (MacroData const * data = buffer().getMacro(name()))
+                               data->definitionData().validate(features);
                }
        }
        features.activeMacros().erase(name());
diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp
index f8d4322cde..6ac335a9a2 100644
--- a/src/mathed/MacroTable.cpp
+++ b/src/mathed/MacroTable.cpp
@@ -39,17 +39,17 @@ namespace lyx {
 /////////////////////////////////////////////////////////////////////
 
 MacroData::MacroData(const Buffer * buf)
-       : buffer_(buf), queried_(true)
+       : buffer_(buf), queried_(true), definition_data_(const_cast<Buffer 
*>(buf))
 {}
 
 
 MacroData::MacroData(Buffer const * buf, DocIterator const & pos)
-       : buffer_(buf), pos_(pos)
+       : buffer_(buf), pos_(pos), definition_data_(const_cast<Buffer *>(buf))
 {}
 
 
 MacroData::MacroData(Buffer const * buf, InsetMathMacroTemplate const & macro)
-       : buffer_(buf)
+       : buffer_(buf), definition_data_(const_cast<Buffer *>(buf))
 {
        queryData(macro);
 }
@@ -146,6 +146,7 @@ void MacroData::queryData(InsetMathMacroTemplate const & 
macro) const
 
        queried_ = true;
        definition_ = macro.definition();
+       asMathData(definition_, definition_data_);
        numargs_ = macro.numArgs();
        display_ = macro.displayDefinition();
        redefinition_ = macro.redefinition();
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index 0c905d6c3c..2042280f51 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -15,6 +15,8 @@
 
 #include "DocIterator.h"
 
+#include "mathed/MathData.h"
+
 #include "support/docstring.h"
 
 #include <map>
@@ -23,8 +25,6 @@
 
 namespace lyx {
 
-class Buffer;
-class MathData;
 class InsetMathMacroTemplate;
 class latexkeys;
 
@@ -47,6 +47,8 @@ public:
        ///
        docstring const & definition() const { updateData(); return 
definition_; }
        ///
+       MathData const & definitionData() const { updateData(); return 
definition_data_; }
+       ///
        docstring const & display() const { updateData(); return display_; }
        /// arity including optional arguments (if there is any)
        size_t numargs() const { updateData(); return numargs_; }
@@ -124,6 +126,8 @@ private:
        ///
        mutable docstring definition_;
        ///
+       mutable MathData definition_data_;
+       ///
        mutable size_t numargs_ = 0;
        ///
        mutable docstring display_;
diff --git a/status.25x b/status.25x
index 3c9b6cc8ff..12540751fe 100644
--- a/status.25x
+++ b/status.25x
@@ -32,6 +32,9 @@ What's new
 - Use cached citation labels for statistics and plaintext to
   improve performance (bug 13322).
 
+- improve performance of code panel with a document with many math
+  macros (bug 13321).
+
 
 * DOCUMENTATION AND LOCALIZATION
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to