[LyX/master] Cache the MathData version of macro definition
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Sat Jun 6 19:36:15 UTC 2026
commit f043262c39126cccdea7e683345cddd0e9ef3962
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
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.
---
src/mathed/InsetMathMacro.cpp | 7 ++-----
src/mathed/MacroTable.cpp | 7 ++++---
src/mathed/MacroTable.h | 8 ++++++--
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 290b461264..8495b53b2c 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_;
More information about the lyx-cvs
mailing list