Do not scan BibTeX files multiple times in a collectBibKeys() procedure.

Scanning is rather slow, so this improves performance in specific
situations (multiple inclusion of larger files in master/child or
chapterbib context)
This commit is contained in:
Juergen Spitzmueller 2017-10-18 09:20:31 +02:00
parent b4294a7b06
commit 88a0666d6c
9 changed files with 26 additions and 16 deletions

View File

@ -2446,15 +2446,16 @@ void Buffer::reloadBibInfoCache() const
return;
d->bibinfo_.clear();
collectBibKeys();
FileNameList checkedFiles;
collectBibKeys(checkedFiles);
d->bibinfo_cache_valid_ = true;
}
void Buffer::collectBibKeys() const
void Buffer::collectBibKeys(FileNameList & checkedFiles) const
{
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
it->collectBibKeys(it);
it->collectBibKeys(it, checkedFiles);
}

View File

@ -17,6 +17,7 @@
#include "support/unique_ptr.h"
#include "support/strfwd.h"
#include "support/types.h"
#include "support/FileNameList.h"
#include <map>
#include <list>
@ -520,7 +521,7 @@ public:
/// or just for it, if it isn't a child.
BiblioInfo const & masterBibInfo() const;
/// collect bibliography info from the various insets in this buffer.
void collectBibKeys() const;
void collectBibKeys(support::FileNameList &) const;
/// add some BiblioInfo to our cache
void addBiblioInfo(BiblioInfo const & bi) const;
/// add a single piece of bibliography info to our cache

View File

@ -23,6 +23,7 @@
#include "support/strfwd.h"
#include "support/types.h"
#include "support/FileNameList.h"
#include <climits>
@ -529,7 +530,7 @@ public:
UpdateType /* utype*/,
TocBackend & /* tocbackend */) const {}
/// Collect BibTeX information
virtual void collectBibKeys(InsetIterator const &) const {}
virtual void collectBibKeys(InsetIterator const &, support::FileNameList &) const {}
/// Update the counters of this inset and of its contents.
/// The boolean indicates whether we are preparing for output, e.g.,
/// of XHTML.

View File

@ -285,7 +285,7 @@ docstring bibitemWidest(Buffer const & buffer, OutputParams const & runparams)
}
void InsetBibitem::collectBibKeys(InsetIterator const & it) const
void InsetBibitem::collectBibKeys(InsetIterator const & it, FileNameList & /*checkedFiles*/) const
{
docstring const key = getParam("key");
docstring const label = getParam("label");

View File

@ -60,7 +60,7 @@ public:
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
///
void collectBibKeys(InsetIterator const &) const;
void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
/// update the counter of this inset
void updateBuffer(ParIterator const &, UpdateType);
///@}

View File

@ -645,13 +645,13 @@ namespace {
} // namespace
void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/) const
void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
{
parseBibTeXFiles();
parseBibTeXFiles(checkedFiles);
}
void InsetBibtex::parseBibTeXFiles() const
void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
{
// This bibtex parser is a first step to parse bibtex files
// more precisely.
@ -678,7 +678,14 @@ void InsetBibtex::parseBibTeXFiles() const
support::FileNamePairList::const_iterator it = files.begin();
support::FileNamePairList::const_iterator en = files.end();
for (; it != en; ++ it) {
ifdocstream ifs(it->second.toFilesystemEncoding().c_str(),
FileName const bibfile = it->second;
if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
// already checked this one. Skip.
continue;
else
// record that we check this.
checkedFiles.push_back(bibfile);
ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
ios_base::in, buffer().masterParams().encoding().iconvName());
char_type ch;

View File

@ -57,7 +57,7 @@ public:
int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
///
void collectBibKeys(InsetIterator const &) const;
void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
///
void validate(LaTeXFeatures &) const;
///
@ -84,7 +84,7 @@ private:
///
void editDatabases() const;
///
void parseBibTeXFiles() const;
void parseBibTeXFiles(support::FileNameList &) const;
///
bool usingBiblatex() const;

View File

@ -1072,7 +1072,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
}
void InsetInclude::collectBibKeys(InsetIterator const & /*di*/) const
void InsetInclude::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
{
Buffer * child = loadIfNeeded();
if (!child)
@ -1082,7 +1082,7 @@ void InsetInclude::collectBibKeys(InsetIterator const & /*di*/) const
// But it'll have to do for now.
if (child == &buffer())
return;
child->collectBibKeys();
child->collectBibKeys(checkedFiles);
}

View File

@ -92,7 +92,7 @@ public:
* \param keys the list of bibkeys in the child buffer.
* \param it not used here
*/
void collectBibKeys(InsetIterator const &) const;
void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
///
bool hasSettings() const { return true; }
///