From: Richard Kimberly Heck Date: Thu, 12 Nov 2020 03:47:57 +0000 (-0500) Subject: Redo the getMacroDefinitions routine. X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d51aa94b67bdda9ddaaf43020598b78e39815906;p=features.git Redo the getMacroDefinitions routine. --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 19012643e0..859f9ce4e3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -215,14 +215,15 @@ public: typedef map MacroDefList; typedef map MacroMap; - pair getMacroDefinitions(docstring const & name) const + bool haveMacro(docstring const & name) const + { return macro_map_.count(name) != 0; } + + // Will assert if there is no such macro, so call haveMacro first! + MacroDefList const & getMacroDefinitions(docstring const & name) const { MacroMap::const_iterator it = macro_map_.find(name); - if (it == macro_map_.end()) { - static MacroDefList dummy; - return {false, dummy}; - } - return {true, it->second}; + LBUFERR(it != macro_map_.end()); + return it->second; } set getMacroNames() const @@ -3634,10 +3635,9 @@ MacroData const * Buffer::Impl::getBufferMacro(docstring const & name, MacroData const * bestData = nullptr; // find macro definitions for name - pair mdl_pair = - macro_table.getMacroDefinitions(name); - if (mdl_pair.first) { - MacroTable::MacroDefList const & mdl = mdl_pair.second; + if (macro_table.haveMacro(name)) { + MacroTable::MacroDefList const & mdl = + macro_table.getMacroDefinitions(name); // find last definition in front of pos MacroTable::MacroDefList::const_iterator it = greatest_below(mdl, pos); @@ -3748,8 +3748,10 @@ MacroData const * Buffer::getMacro(docstring const & name, { // look where the child buffer is included first Impl::BufferPositionMap::iterator it = d->children_positions.find(&child); - if (it == d->children_positions.end()) + if (it == d->children_positions.end()) { + LYXERR0("Querying parent for macro when we are not a child!"); return nullptr; + } // check for macros at the inclusion position return getMacro(name, it->second, global);