Jürgen Spitzmüller wrote:
Abdelrazak Younes wrote:
The scanning of the bibtex files should be independent of the loaded
Buffer. Imagine you have two Buffers using the same bibtex file, the
same scanning will need to be done twice for no reason. Or maybe I am
missing something?
You're right, that could be optimized. However, I don't think the performance
gain will be that big. Scanning for the files once for each document (or even
once more if the bibtex inset is modified) is bearable IMHO.
Georg said that in his case it could be as long as 20 seconds because of
this scanning. That's why I talked about that since the beginning.
Before I have introduced the bibfiles cache (i.e., from 1.4.0 to 1.4.2), the
scanning has been done for every single citation inset in the file over all
bibtex files (and every time you opened the citation dialog), as soon as the
inset was displayed. That made editing (and scrolling in particular) of
documents with natbib citations unusable, whereas the situation now is
absolutely fine IMHO.
Could you test the attached patch nevertheless? Or Georg maybe?
Abdel.
Index: insetbibtex.C
===================================================================
--- insetbibtex.C (revision 16588)
+++ insetbibtex.C (working copy)
@@ -33,7 +33,16 @@
#include <boost/tokenizer.hpp>
+#include <map>
+using std::endl;
+using std::getline;
+using std::string;
+using std::ostream;
+using std::map;
+using std::pair;
+using std::vector;
+
namespace lyx {
using support::absolutePath;
@@ -61,14 +70,7 @@
namespace Alert = frontend::Alert;
namespace os = support::os;
-using std::endl;
-using std::getline;
-using std::string;
-using std::ostream;
-using std::pair;
-using std::vector;
-
InsetBibtex::InsetBibtex(InsetCommandParams const & p)
: InsetCommand(p, "bibtex")
{}
@@ -308,18 +310,30 @@
vector<FileName> vec;
+ typedef map<string, FileName> BibCache;
+ static map<string, FileName> bib_cache;
+
+
string tmp;
// FIXME UNICODE
string bibfiles = to_utf8(getParam("bibfiles"));
bibfiles = split(bibfiles, tmp, ',');
while (!tmp.empty()) {
- FileName const file = findtexfile(changeExtension(tmp, "bib"),
"bib");
- lyxerr[Debug::LATEX] << "Bibfile: " << file << endl;
+ string bibcode = changeExtension(tmp, "bib");
+ BibCache::const_iterator it = bib_cache.find(bibcode);
+ if (it == bib_cache.end()) {
+ FileName const file = findtexfile(bibcode, "bib");
+ // If we didn't find a matching file name just fail
silently
+ if (!file.empty()) {
+ bib_cache[bibcode] = file;
+ vec.push_back(file);
+ lyxerr[Debug::LATEX] << "Bibfile: " << file <<
endl;
+ }
+ } else {
+ vec.push_back(it->second);
+ lyxerr[Debug::LATEX] << "Bibfile: " << it->second <<
endl;
+ }
- // If we didn't find a matching file name just fail silently
- if (!file.empty())
- vec.push_back(file);
-
// Get next file name
bibfiles = split(bibfiles, tmp, ',');
}