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
This commit is contained in:
Enrico Forestieri 2009-11-08 18:47:33 +00:00
parent 83c0e43068
commit f83a6cc3af
6 changed files with 23 additions and 10 deletions

View File

@ -705,6 +705,7 @@ bool Buffer::readDocument(Lexer & lex)
// read main text // read main text
bool const res = text().read(lex, errorList, d->inset); bool const res = text().read(lex, errorList, d->inset);
usermacros.clear();
updateMacros(); updateMacros();
updateMacroInstances(); updateMacroInstances();
return res; return res;

View File

@ -21,6 +21,7 @@
#include "support/SignalSlot.h" #include "support/SignalSlot.h"
#include <list> #include <list>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
@ -429,6 +430,10 @@ public:
/// Return macro defined before the inclusion of the child /// Return macro defined before the inclusion of the child
MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const; 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 /// Replace the inset contents for insets which InsetCode is equal
/// to the passed \p inset_code. /// to the passed \p inset_code.
void changeRefsIfUnique(docstring const & from, docstring const & to, void changeRefsIfUnique(docstring const & from, docstring const & to,

View File

@ -1637,7 +1637,7 @@ void InsetMathHull::write(ostream & os) const
void InsetMathHull::read(Lexer & lex) void InsetMathHull::read(Lexer & lex)
{ {
MathAtom at; MathAtom at;
mathed_parse_normal(buffer_, at, lex, Parse::NORMAL); mathed_parse_normal(buffer_, at, lex, Parse::TRACKMACRO);
operator=(*at->asHullInset()); operator=(*at->asHullInset());
} }

View File

@ -1108,7 +1108,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
void MathMacroTemplate::read(Lexer & lex) void MathMacroTemplate::read(Lexer & lex)
{ {
MathData ar(buffer_); 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()) { if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
lyxerr << "Cannot read macro from '" << ar << "'" << endl; lyxerr << "Cannot read macro from '" << ar << "'" << endl;
lyxerr << "Read: " << to_utf8(asString(ar)) << endl; lyxerr << "Read: " << to_utf8(asString(ar)) << endl;

View File

@ -442,8 +442,6 @@ Parser::Parser(Lexer & lexer, parse_mode mode, Buffer * buf)
: lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true), : lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true),
buffer_(buf) buffer_(buf)
{ {
if (buf)
buf->updateMacros();
tokenize(lexer.getStream()); tokenize(lexer.getStream());
lexer.eatLine(); lexer.eatLine();
} }
@ -452,8 +450,6 @@ Parser::Parser(Lexer & lexer, parse_mode mode, Buffer * buf)
Parser::Parser(istream & is, parse_mode mode, Buffer * buf) Parser::Parser(istream & is, parse_mode mode, Buffer * buf)
: lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf) : lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
{ {
if (buf)
buf->updateMacros();
tokenize(is); 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) Parser::Parser(docstring const & str, parse_mode mode, Buffer * buf)
: lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf) : lineno_(0), pos_(0), mode_(mode), success_(true), buffer_(buf)
{ {
if (buf)
buf->updateMacros();
tokenize(str); tokenize(str);
} }
@ -1021,6 +1015,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
cell->push_back(MathAtom(new MathMacroTemplate(buf, cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, 0, MacroTypeDef, name, nargs, 0, MacroTypeDef,
vector<MathData>(), def, display))); vector<MathData>(), def, display)));
if (buf && (mode_ & Parse::TRACKMACRO))
buf->usermacros.insert(name);
} }
else if (t.cs() == "newcommand" || else if (t.cs() == "newcommand" ||
@ -1066,6 +1063,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
cell->push_back(MathAtom(new MathMacroTemplate(buf, cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, optionals, MacroTypeNewcommand, name, nargs, optionals, MacroTypeNewcommand,
optionalValues, def, display))); optionalValues, def, display)));
if (buf && (mode_ & Parse::TRACKMACRO))
buf->usermacros.insert(name);
} }
else if (t.cs() == "newcommandx" || else if (t.cs() == "newcommandx" ||
@ -1184,6 +1184,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
cell->push_back(MathAtom(new MathMacroTemplate(buf, cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, optionals, MacroTypeNewcommandx, name, nargs, optionals, MacroTypeNewcommandx,
optionalValues, def, display))); optionalValues, def, display)));
if (buf && (mode_ & Parse::TRACKMACRO))
buf->usermacros.insert(name);
} }
else if (t.cs() == "(") { else if (t.cs() == "(") {
@ -1763,7 +1766,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
else if (t.cs().size()) { else if (t.cs().size()) {
bool const is_user_macro = 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()); latexkeys const * l = in_word_set(t.cs());
if (l && !is_user_macro) { if (l && !is_user_macro) {
if (l->inset == "big") { if (l->inset == "big") {

View File

@ -26,7 +26,9 @@ enum flags {
/// Quiet operation (no warnigs or errors). /// Quiet operation (no warnigs or errors).
QUIET = 0x04, QUIET = 0x04,
/// Wrap unicode symbols in \text{}. /// Wrap unicode symbols in \text{}.
USETEXT = 0x08 USETEXT = 0x08,
/// Track macro creation while loading a document
TRACKMACRO = 0x10
}; };