Using updateMacros() entails a performance hit when loading a document
with really a lot of macros. So, revert to the original strategy of
tracking macros at creation time. In order to also account for macros
defined in a child document, the child is now loaded by the include inset
at construction time instead of after the master has finished loading.
This strategy mimics what updateMacros() was accomplishing without
incurring in its drawbacks, such that loading time is practically
unchanged even with a thousand macros.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36968
a592a061-630c-0410-9148-
cb99ea01b6c8
// read main text
bool const res = text().read(lex, errorList, d->inset);
+ // inform parent buffer about local macros
+ if (parent()) {
+ Buffer * pbuf = const_cast<Buffer *>(parent());
+ UserMacroSet::const_iterator cit = usermacros.begin();
+ UserMacroSet::const_iterator end = usermacros.end();
+ for (; cit != end; ++cit)
+ pbuf->usermacros.insert(*cit);
+ }
+ usermacros.clear();
updateMacros();
updateMacroInstances();
return res;
/// 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,
#include "insets/InsetListingsParams.h"
#include "insets/RenderPreview.h"
+#include "mathed/MacroTable.h"
+
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
if (isListings(params())) {
InsetListingsParams listing_params(to_utf8(p["lstparams"]));
label_ = createLabel(buffer_, from_utf8(listing_params.getParamValue("label")));
- }
+ } else if (isInputOrInclude(params()) && buf)
+ loadIfNeeded();
}
// Buffer creation is not possible.
return 0;
+ // Set parent before loading, such that macros can be tracked
+ child->setParent(&buffer());
+
if (child->loadLyXFile() != Buffer::ReadSuccess) {
failedtoload_ = true;
+ child->setParent(0);
//close the buffer we just opened
theBufferList().release(child);
return 0;
}
-
+
if (!child->errorList("Parse").empty()) {
// FIXME: Do something.
}
+ } else {
+ // The file was already loaded, so, simply
+ // inform parent buffer about local macros.
+ Buffer * parent = const_cast<Buffer *>(&buffer());
+ child->setParent(parent);
+ MacroNameSet macros;
+ child->listMacroNames(macros);
+ MacroNameSet::const_iterator cit = macros.begin();
+ MacroNameSet::const_iterator end = macros.end();
+ for (; cit != end; ++cit)
+ parent->usermacros.insert(*cit);
}
- child->setParent(&buffer());
+
// Cache the child buffer.
child_buffer_ = child;
return child;
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" ||
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" ||
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().size()) {
- latexkeys const * l = in_word_set(t.cs());
-
- if (buf && (mode_ & Parse::TRACKMACRO) && l)
- buf->updateMacros();
+ bool const no_mhchem =
+ (t.cs() == "ce" || t.cs() == "cf")
+ && buf && buf->params().use_mhchem ==
+ BufferParams::package_off;
- bool const is_user_macro =
- (buf && buf->getMacro(t.cs(), false) != 0);
+ bool const is_user_macro = no_mhchem ||
+ (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") {
skipSpaces();