The branch, cleanup/updateMacros, has been updated.

- Log -----------------------------------------------------------------

commit 4a6d50251a59f6f817ecbbbdb0d3295ee6a3bf5b
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 15:56:01 2020 -0500

    Some comments and some minor re-organization

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7ed1685..7237737 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -214,7 +214,6 @@ public:
        NamePositionScopeMacroMap macros;
 
        /// positions of child buffers in the buffer
-       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
        struct ScopeBuffer {
                ScopeBuffer() : buffer(nullptr) {}
                ScopeBuffer(DocIterator const & s, Buffer const * b)
@@ -222,10 +221,11 @@ public:
                DocIterator scope;
                Buffer const * buffer;
        };
-       typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
        /// position of children buffers in this buffer
+       typedef map<Buffer const * const, DocIterator> BufferPositionMap;
        BufferPositionMap children_positions;
        /// map from children inclusion positions to their scope and their 
buffer
+       typedef map<DocIterator, ScopeBuffer> PositionScopeBufferMap;
        PositionScopeBufferMap position_to_children;
 
        /// Contains the old buffer filePath() while saving-as, or the
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index ab3c6b4..a6996da 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -112,6 +112,10 @@ private:
        void updateData() const;
        ///
        Buffer const * buffer_;
+       // FIXME This is probably a large part of why updateMacros is 
+       // so expensive. We are, it would seem, recreating these objects
+       // from scratch each time through. That seems unnecessary, if what
+       // usually needs updating is just the pos_ member.
        /// The position of the definition in the buffer.
        /// There is no guarantee it stays valid if the buffer
        /// changes. But it (normally) exists only until the
@@ -121,13 +125,20 @@ private:
        /// returns its defaults values and the user sees unfolded
        /// macros.
        mutable DocIterator pos_;
-       ///
+       /// flag that tells us whether our cached info is valid. used
+       /// with lazy version.
        mutable bool queried_ = false;
-       ///
+       // At the moment, it seems to me as if most of the other members
+       // could be replaced by a pointer to the associated macro (and so
+       // that one eliminated. I.e.:
+       //    InsetMathMacroTemplate const * const ourmacro_;
+       //    docstring definition() { return ourmacro_->definition(); }
+       // etc.
+       /// the macro definition
        mutable docstring definition_;
        ///
        mutable size_t numargs_ = 0;
-       ///
+       /// what we use (a kind of LyX macro) for display in the work area
        mutable docstring display_;
        ///
        latexkeys const * sym_ = nullptr;

commit 3dddcefc3c8ee388003d3af67dc825163c6ed456
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon Nov 9 15:39:20 2020 -0500

    Properly implement the singleton pattern

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 44b3178..7ed1685 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3686,7 +3686,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
        }
 
        if (global) {
-               data = MacroTable::globalMacros().get(name);
+               data = MacroTable::get().getMacro(name);
                if (data != nullptr)
                        return data;
        }
diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 57294c0..600562f 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -938,7 +938,7 @@ MacroData const * InsetMathMacro::macroBackup() const
 {
        if (macro())
                return &d->macroBackup_;
-       if (MacroData const * data = MacroTable::globalMacros().get(name()))
+       if (MacroData const * data = MacroTable::get().getMacro(name()))
                return data;
        return nullptr;
 }
@@ -957,7 +957,7 @@ void InsetMathMacro::validate(LaTeXFeatures & features) 
const
                features.require(d->required_);
        else if (!d->macro_) {
                // Update requires for known global macros.
-               MacroData const * data = MacroTable::globalMacros().get(name());
+               MacroData const * data = MacroTable::get().getMacro(name());
                if (data && !data->required().empty())
                        features.require(data->required());
        }
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index ada0400..19aa745 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -2106,7 +2106,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
 
        // fill in global macros
        macros.clear();
-       MacroTable::globalMacros().getMacroNames(macros, false);
+       MacroTable::get().getMacroNames(macros, false);
        //lyxerr << "Globals completion macros: ";
        for (it = macros.begin(); it != macros.end(); ++it) {
                //lyxerr << "\\" + *it << " ";
diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp
index 218c849..2bc427b 100644
--- a/src/mathed/MacroTable.cpp
+++ b/src/mathed/MacroTable.cpp
@@ -215,14 +215,14 @@ int MacroData::write(odocstream & os, bool 
overwriteRedefinition) const
 //
 /////////////////////////////////////////////////////////////////////
 
-MacroTable & MacroTable::globalMacros()
+MacroTable & MacroTable::get()
 {
        static MacroTable theGlobalMacros;
        return theGlobalMacros;
 }
 
 
-MacroData const * MacroTable::get(docstring const & name) const
+MacroData const * MacroTable::getMacro(docstring const & name) const
 {
        const_iterator it = find(name);
        return it == end() ? 0 : &it->second;
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index 77b306f..ab3c6b4 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -160,19 +160,22 @@ class MacroSet : public std::set<MacroData const *> {};
 class MacroTable : public std::map<docstring, MacroData>
 {
 public:
+       /// We are a singleton
+       MacroTable() = default;
+       MacroTable(MacroTable const &) = delete;
+       void operator=(MacroTable const &) = delete;
+       /// the global list: our unique instance
+       static MacroTable & get();
        /// Parse full "\\def..." or "\\newcommand..." or ...
        iterator insert(Buffer * buf, docstring const & definition);
        /// Insert pre-digested macro definition
        iterator insert(docstring const & name, MacroData const & data);
        ///
-       MacroData const * get(docstring const & name) const;
+       MacroData const * getMacro(docstring const & name) const;
        ///
        void dump();
        ///
        void getMacroNames(std::set<docstring> & names, bool gethidden) const;
-
-       /// the global list
-       static MacroTable & globalMacros();
 };
 
 
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 54fe012..f956973 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -202,7 +202,7 @@ void initSymbols()
                                        required = "";
                        } else
                                htmlname = xmlname = "";
-                       MacroTable::iterator it = 
MacroTable::globalMacros().insert(
+                       MacroTable::iterator it = MacroTable::get().insert(
                                        0, from_utf8(macro));
                        if (!extra.empty() || !htmlname.empty() || 
!xmlname.empty() || !required.empty()) {
                                MathWordList::iterator wit = 
theMathWordList.find(it->first);

-----------------------------------------------------------------------

Summary of changes:
 src/Buffer.cpp                |    6 +++---
 src/mathed/InsetMathMacro.cpp |    4 ++--
 src/mathed/InsetMathNest.cpp  |    2 +-
 src/mathed/MacroTable.cpp     |    4 ++--
 src/mathed/MacroTable.h       |   28 +++++++++++++++++++++-------
 src/mathed/MathFactory.cpp    |    2 +-
 6 files changed, 30 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
Repository for new features
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to