mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
Introduce a labels&references cache at buffer level. This cache uses the already existing updateLabels() mechanism and thus speedups labels&references toc generation. As a bonus, duplicates labels and broken references are detected and tagged with "DUPLICATE:" and "BROKEN:" in the outliner (or the navigator).
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23389 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2f0b39a495
commit
8e9dc9bd2a
@ -100,10 +100,12 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
@ -117,10 +119,10 @@ namespace {
|
||||
|
||||
int const LYX_FORMAT = 316; // JSpitzm: subfig support
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
typedef map<string, bool> DepClean;
|
||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||
|
||||
} // namespace anon
|
||||
|
||||
class Buffer::Impl
|
||||
{
|
||||
@ -205,6 +207,8 @@ public:
|
||||
/// A cache for the bibfiles (including bibfiles of loaded child
|
||||
/// documents), needed for appropriate update of natbib labels.
|
||||
mutable EmbeddedFileList bibfilesCache_;
|
||||
|
||||
mutable RefCache ref_cache_;
|
||||
};
|
||||
|
||||
/// Creates the per buffer temporary directory
|
||||
@ -2064,6 +2068,47 @@ void Buffer::writeParentMacros(odocstream & os) const
|
||||
}
|
||||
|
||||
|
||||
Buffer::References & Buffer::references(docstring const & label)
|
||||
{
|
||||
if (d->parent_buffer)
|
||||
return const_cast<Buffer *>(masterBuffer())->references(label);
|
||||
|
||||
RefCache::iterator it = d->ref_cache_.find(label);
|
||||
if (it != d->ref_cache_.end())
|
||||
return it->second.second;
|
||||
|
||||
static InsetLabel const * dummy_il = 0;
|
||||
static References const dummy_refs;
|
||||
it = d->ref_cache_.insert(make_pair(label, make_pair(dummy_il, dummy_refs))).first;
|
||||
return it->second.second;
|
||||
}
|
||||
|
||||
|
||||
Buffer::References const & Buffer::references(docstring const & label) const
|
||||
{
|
||||
return const_cast<Buffer *>(this)->references(label);
|
||||
}
|
||||
|
||||
|
||||
void Buffer::setInsetLabel(docstring const & label, InsetLabel const * il)
|
||||
{
|
||||
masterBuffer()->d->ref_cache_[label].first = il;
|
||||
}
|
||||
|
||||
|
||||
InsetLabel const * Buffer::insetLabel(docstring const & label) const
|
||||
{
|
||||
return masterBuffer()->d->ref_cache_[label].first;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::clearReferenceCache() const
|
||||
{
|
||||
if (!d->parent_buffer)
|
||||
d->ref_cache_.clear();
|
||||
}
|
||||
|
||||
|
||||
void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
|
||||
InsetCode code)
|
||||
{
|
||||
@ -2327,9 +2372,6 @@ void Buffer::resetChildDocuments(bool close_them) const
|
||||
resetParentBuffer(this, ip, close_them);
|
||||
}
|
||||
|
||||
if (use_gui && masterBuffer() == this)
|
||||
updateLabels(*this);
|
||||
|
||||
// clear references to children in macro tables
|
||||
d->children_positions.clear();
|
||||
d->position_to_children.clear();
|
||||
|
12
src/Buffer.h
12
src/Buffer.h
@ -31,6 +31,8 @@ class ErrorItem;
|
||||
class ErrorList;
|
||||
class FuncRequest;
|
||||
class Inset;
|
||||
class InsetRef;
|
||||
class InsetLabel;
|
||||
class Font;
|
||||
class Format;
|
||||
class Lexer;
|
||||
@ -451,7 +453,15 @@ public:
|
||||
bool isExportable(std::string const & format) const;
|
||||
///
|
||||
std::vector<Format const *> exportableFormats(bool only_viewable) const;
|
||||
|
||||
|
||||
///
|
||||
typedef std::vector<std::pair<InsetRef *, ParIterator> > References;
|
||||
References & references(docstring const & label);
|
||||
References const & references(docstring const & label) const;
|
||||
void clearReferenceCache() const;
|
||||
void setInsetLabel(docstring const & label, InsetLabel const * il);
|
||||
InsetLabel const * insetLabel(docstring const & label) const;
|
||||
|
||||
private:
|
||||
/// search for macro in local (buffer) table or in children
|
||||
MacroData const * getBufferMacro(docstring const & name,
|
||||
|
@ -491,6 +491,7 @@ void updateLabels(Buffer const & buf, bool childonly)
|
||||
|
||||
// start over the counters
|
||||
textclass.counters().reset();
|
||||
buf.clearReferenceCache();
|
||||
}
|
||||
|
||||
Buffer & cbuf = const_cast<Buffer &>(buf);
|
||||
|
@ -12,17 +12,23 @@
|
||||
|
||||
#include "InsetLabel.h"
|
||||
|
||||
#include "InsetRef.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "InsetIterator.h"
|
||||
#include "ParIterator.h"
|
||||
#include "sgml.h"
|
||||
#include "Text.h"
|
||||
#include "TocBackend.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
@ -57,10 +63,32 @@ docstring InsetLabel::screenLabel() const
|
||||
}
|
||||
|
||||
|
||||
void InsetLabel::updateLabels(ParIterator const & it)
|
||||
{
|
||||
docstring const & label = getParam("name");
|
||||
if (buffer().insetLabel(label))
|
||||
// Problem: We already have an InsetLabel with the same name!
|
||||
return;
|
||||
buffer().setInsetLabel(label, this);
|
||||
}
|
||||
|
||||
|
||||
void InsetLabel::addToToc(ParConstIterator const & cpit) const
|
||||
{
|
||||
docstring const & label = getParam("name");
|
||||
Toc & toc = buffer().tocBackend().toc("label");
|
||||
toc.push_back(TocItem(cpit, 0, screenLabel()));
|
||||
if (buffer().insetLabel(label) != this) {
|
||||
toc.push_back(TocItem(cpit, 0, _("DUPLICATE: ") + label));
|
||||
return;
|
||||
}
|
||||
toc.push_back(TocItem(cpit, 0, label));
|
||||
Buffer::References const & refs = buffer().references(label);
|
||||
Buffer::References::const_iterator it = refs.begin();
|
||||
Buffer::References::const_iterator end = refs.end();
|
||||
for (; it != end; ++it) {
|
||||
ParConstIterator const ref_pit(it->second);
|
||||
toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
static bool isCompatibleCommand(std::string const & s)
|
||||
{ return s == "label"; }
|
||||
///
|
||||
void updateLabels(ParIterator const & it);
|
||||
///
|
||||
void addToToc(ParConstIterator const &) const;
|
||||
protected:
|
||||
///
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -152,32 +152,23 @@ void InsetRef::textString(odocstream & os) const
|
||||
}
|
||||
|
||||
|
||||
void InsetRef::updateLabels(ParIterator const & it)
|
||||
{
|
||||
docstring const & label = getParam("reference");
|
||||
buffer().references(label).push_back(make_pair(this, it));
|
||||
}
|
||||
|
||||
|
||||
void InsetRef::addToToc(ParConstIterator const & cpit) const
|
||||
{
|
||||
docstring const & label = getParam("reference");
|
||||
Toc & toc = buffer().tocBackend().toc("label");
|
||||
Toc::iterator it = toc.begin();
|
||||
Toc::iterator end = toc.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->str() == label)
|
||||
break;
|
||||
}
|
||||
|
||||
docstring const reflabel = screenLabel();
|
||||
if (it == end) {
|
||||
// This label has not been parsed yet so we just add it temporarily.
|
||||
// InsetLabel::addTocToc() will fix that later.
|
||||
toc.push_back(TocItem(cpit, 0, label));
|
||||
toc.push_back(TocItem(cpit, 1, reflabel));
|
||||
if (buffer().insetLabel(label))
|
||||
// This InsetRef has already been taken care of in InsetLabel::addToToc().
|
||||
return;
|
||||
}
|
||||
|
||||
// The Toc item for this label already exists so let's add
|
||||
// this inset to this node.
|
||||
++it;
|
||||
while (it != end && it->str() == reflabel)
|
||||
++it;
|
||||
toc.insert(it, TocItem(cpit, 1, reflabel));
|
||||
Toc & toc = buffer().tocBackend().toc("label");
|
||||
docstring const reflabel = _("BROKEN: ") + screenLabel();
|
||||
toc.push_back(TocItem(cpit, 0, reflabel));
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
///
|
||||
static bool isCompatibleCommand(std::string const & s);
|
||||
///
|
||||
void updateLabels(ParIterator const & it);
|
||||
///
|
||||
void addToToc(ParConstIterator const &) const;
|
||||
protected:
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user