]> git.lyx.org Git - features.git/commitdiff
Don't use updateMacros() in the math parser, in order to avoid
authorEnrico Forestieri <forenr@lyx.org>
Sun, 8 Nov 2009 18:47:33 +0000 (18:47 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 8 Nov 2009 18:47:33 +0000 (18:47 +0000)
performance problems when loading documents with lots of macros.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31907 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/mathed/InsetMathHull.cpp
src/mathed/MathMacroTemplate.cpp
src/mathed/MathParser.cpp
src/mathed/MathParser_flags.h

index 1bca5adbc9976522f1a9abbab9daa68aa4fadd26..ba10cd732720d094239d30dc68ac1dc2e039a80a 100644 (file)
@@ -705,6 +705,7 @@ bool Buffer::readDocument(Lexer & lex)
        // read main text
        bool const res = text().read(lex, errorList, d->inset);
 
+       usermacros.clear();
        updateMacros();
        updateMacroInstances();
        return res;
index be7caa6519dda100609f249cf8e7af1e9f57481f..510ea4baf0e26e947ea01395285d5a194b1eb9c6 100644 (file)
@@ -21,6 +21,7 @@
 #include "support/SignalSlot.h"
 
 #include <list>
+#include <set>
 #include <string>
 #include <vector>
 
@@ -429,6 +430,10 @@ public:
        /// Return macro defined before the inclusion of the child
        MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
 
+       /// Collect user macro names at loading time
+       typedef std::set<docstring> UserMacroSet;
+       UserMacroSet usermacros;
+
        /// Replace the inset contents for insets which InsetCode is equal
        /// to the passed \p inset_code.
        void changeRefsIfUnique(docstring const & from, docstring const & to,
index c1b17b85a16b7b026719eba7e7a42befe6d3b1bc..d68e3bc74257015ae7fa05653b43e122df3624bd 100644 (file)
@@ -1637,7 +1637,7 @@ void InsetMathHull::write(ostream & os) const
 void InsetMathHull::read(Lexer & lex)
 {
        MathAtom at;
-       mathed_parse_normal(buffer_, at, lex, Parse::NORMAL);
+       mathed_parse_normal(buffer_, at, lex, Parse::TRACKMACRO);
        operator=(*at->asHullInset());
 }
 
index 257c55f639e867657a73fefb49e56a1a2a14ea2d..8e809e3b2143f93adc68cf4ca027980362ec6640 100644 (file)
@@ -1108,7 +1108,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
 void MathMacroTemplate::read(Lexer & lex)
 {
        MathData ar(buffer_);
-       mathed_parse_cell(ar, lex.getStream(), Parse::NORMAL);
+       mathed_parse_cell(ar, lex.getStream(), Parse::TRACKMACRO);
        if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
                lyxerr << "Cannot read macro from '" << ar << "'" << endl;
                lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
index bf1e27cee86f4f9023eab22a5bff6b4af470c006..bc90a37091c7781670147169f666dbdf3b527ac2 100644 (file)
@@ -442,8 +442,6 @@ Parser::Parser(Lexer & lexer, parse_mode mode, Buffer * buf)
        : lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true),
          buffer_(buf)
 {
-       if (buf)
-               buf->updateMacros();
        tokenize(lexer.getStream());
        lexer.eatLine();
 }
@@ -452,8 +450,6 @@ Parser::Parser(Lexer & lexer, parse_mode mode, Buffer * buf)
 Parser::Parser(istream & is, parse_mode mode, Buffer * buf)
        : lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
 {
-       if (buf)
-               buf->updateMacros();
        tokenize(is);
 }
 
@@ -461,8 +457,6 @@ Parser::Parser(istream & is, parse_mode mode, Buffer * buf)
 Parser::Parser(docstring const & str, parse_mode mode, Buffer * buf)
        : lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
 {
-       if (buf)
-               buf->updateMacros();
        tokenize(str);
 }
 
@@ -1021,6 +1015,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        cell->push_back(MathAtom(new MathMacroTemplate(buf,
                                name, nargs, 0, MacroTypeDef,
                                vector<MathData>(), def, display)));
+
+                       if (buf && (mode_ & Parse::TRACKMACRO))
+                               buf->usermacros.insert(name);
                }
                
                else if (t.cs() == "newcommand" ||
@@ -1066,6 +1063,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        cell->push_back(MathAtom(new MathMacroTemplate(buf,
                                name, nargs, optionals, MacroTypeNewcommand,
                                optionalValues, def, display)));
+
+                       if (buf && (mode_ & Parse::TRACKMACRO))
+                               buf->usermacros.insert(name);
                }
                
                else if (t.cs() == "newcommandx" ||
@@ -1184,6 +1184,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        cell->push_back(MathAtom(new MathMacroTemplate(buf,
                                name, nargs, optionals, MacroTypeNewcommandx,
                                optionalValues, def, display)));
+
+                       if (buf && (mode_ & Parse::TRACKMACRO))
+                               buf->usermacros.insert(name);
                }
 
                else if (t.cs() == "(") {
@@ -1763,7 +1766,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                else if (t.cs().size()) {
                        bool const is_user_macro =
-                               buf && buf->getMacro(t.cs(), false);
+                               buf && (mode_ & Parse::TRACKMACRO
+                                       ? buf->usermacros.count(t.cs()) != 0
+                                       : buf->getMacro(t.cs(), false) != 0);
                        latexkeys const * l = in_word_set(t.cs());
                        if (l && !is_user_macro) {
                                if (l->inset == "big") {
index 06f864bd96ce63b7fca4eb670836ffc27a62c06f..9c9c4a3b95e7f204f27d5ed3adca3552655fdb03 100644 (file)
@@ -26,7 +26,9 @@ enum flags {
        /// Quiet operation (no warnigs or errors).
        QUIET = 0x04,
        /// Wrap unicode symbols in \text{}.
-       USETEXT = 0x08
+       USETEXT = 0x08,
+       /// Track macro creation while loading a document
+       TRACKMACRO = 0x10
 };