]> git.lyx.org Git - features.git/commitdiff
Do not scan BibTeX files multiple times in a collectBibKeys() procedure.
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 18 Oct 2017 07:20:31 +0000 (09:20 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 18 Oct 2017 10:21:29 +0000 (12:21 +0200)
Scanning is rather slow, so this improves performance in specific
situations (multiple inclusion of larger files in master/child or
chapterbib context)

(cherry picked from commit 88a0666d6c039decfbd0da0dee6c9b4ba4923806)

src/Buffer.cpp
src/Buffer.h
src/insets/Inset.h
src/insets/InsetBibitem.cpp
src/insets/InsetBibitem.h
src/insets/InsetBibtex.cpp
src/insets/InsetBibtex.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h

index c4ce8ea053d45633e4ace7f8f3c4463e26047b14..9ec20e0fbbcb09b24277260cb8e453a4767dd89c 100644 (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);
 }
 
 
index 165f5d8795a1ae218c3fe2de406cd06e4ce04567..35e76329733b9765ba1b522a47606c34ab8d4a4b 100644 (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
index 578a7f4d5a1a9541a37a2c40e8b928fd2f6861a7..94e9d1a6687a31ccc17266374719ed641887a402 100644 (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.
index afc30ae37d395647c16ac4391912fb0ea43c835d..d5ebaf7640c723422952e0c602f2d05343a983ae 100644 (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");
index 41497e18497f48ac185baafe37c29a156a7153a7..ba33732ad0b01d33a7ee6c6ce02d1df6235b508e 100644 (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);
        ///@}
index a90511077365d563a34635cc79d4743a31560244..30b169acb07ff5d0d0a80c402b9e54b508668ede 100644 (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;
index 3ba96a29e817d14fb7616b36279a572f0d9974b7..2d033464f0a6409a0a1309d124622c26fba66d07 100644 (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;
 
index 6af715fb22ec71cd37dece06be5d96a00f2711d6..d6e3ae2c63f9a7e808b6d0f62dd557b17528cc43 100644 (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);
 }
 
 
index 7be5f7892d3231ff9f5b0131aac5243b128d6eb9..009b49e3ac03c06b9ca4e55b72a677f3a41e157a 100644 (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; }
        ///