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
// read main text
bool const res = text().read(lex, errorList, d->inset);
// read main text
bool const res = text().read(lex, errorList, d->inset);
updateMacros();
updateMacroInstances();
return res;
updateMacros();
updateMacroInstances();
return res;
#include "support/SignalSlot.h"
#include <list>
#include "support/SignalSlot.h"
#include <list>
#include <string>
#include <vector>
#include <string>
#include <vector>
/// Return macro defined before the inclusion of the child
MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
/// 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,
/// Replace the inset contents for insets which InsetCode is equal
/// to the passed \p inset_code.
void changeRefsIfUnique(docstring const & from, docstring const & to,
void InsetMathHull::read(Lexer & lex)
{
MathAtom at;
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());
}
operator=(*at->asHullInset());
}
void MathMacroTemplate::read(Lexer & lex)
{
MathData ar(buffer_);
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;
if (ar.size() != 1 || !ar[0]->asMacroTemplate()) {
lyxerr << "Cannot read macro from '" << ar << "'" << endl;
lyxerr << "Read: " << to_utf8(asString(ar)) << endl;
: lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true),
buffer_(buf)
{
: lineno_(lexer.lineNumber()), pos_(0), mode_(mode), success_(true),
buffer_(buf)
{
- if (buf)
- buf->updateMacros();
tokenize(lexer.getStream());
lexer.eatLine();
}
tokenize(lexer.getStream());
lexer.eatLine();
}
Parser::Parser(istream & is, parse_mode mode, Buffer * buf)
: lineno_(0), pos_(0), mode_(mode), success_(true), 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();
Parser::Parser(docstring const & str, parse_mode mode, Buffer * buf)
: lineno_(0), pos_(0), mode_(mode), success_(true), 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();
cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, 0, MacroTypeDef,
vector<MathData>(), def, display)));
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" ||
}
else if (t.cs() == "newcommand" ||
cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, optionals, MacroTypeNewcommand,
optionalValues, def, display)));
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" ||
}
else if (t.cs() == "newcommandx" ||
cell->push_back(MathAtom(new MathMacroTemplate(buf,
name, nargs, optionals, MacroTypeNewcommandx,
optionalValues, def, display)));
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() == "(") {
}
else if (t.cs() == "(") {
else if (t.cs().size()) {
bool const is_user_macro =
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") {
latexkeys const * l = in_word_set(t.cs());
if (l && !is_user_macro) {
if (l->inset == "big") {
/// Quiet operation (no warnigs or errors).
QUIET = 0x04,
/// Wrap unicode symbols in \text{}.
/// Quiet operation (no warnigs or errors).
QUIET = 0x04,
/// Wrap unicode symbols in \text{}.
+ USETEXT = 0x08,
+ /// Track macro creation while loading a document
+ TRACKMACRO = 0x10