From: Enrico Forestieri Date: Sun, 8 Nov 2009 18:47:33 +0000 (+0000) Subject: Don't use updateMacros() in the math parser, in order to avoid X-Git-Tag: 2.0.0~5198 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f83a6cc3af6bbb88f558ef1d974156da15fd66a3;p=features.git Don't use updateMacros() in the math parser, in order to avoid 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 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 1bca5adbc9..ba10cd7327 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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; diff --git a/src/Buffer.h b/src/Buffer.h index be7caa6519..510ea4baf0 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -21,6 +21,7 @@ #include "support/SignalSlot.h" #include +#include #include #include @@ -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 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, diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index c1b17b85a1..d68e3bc742 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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()); } diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index 257c55f639..8e809e3b21 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -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; diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index bf1e27cee8..bc90a37091 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -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(), 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") { diff --git a/src/mathed/MathParser_flags.h b/src/mathed/MathParser_flags.h index 06f864bd96..9c9c4a3b95 100644 --- a/src/mathed/MathParser_flags.h +++ b/src/mathed/MathParser_flags.h @@ -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 };