[LyX/master] Clear info_ cache if format changes

Juergen Spitzmueller spitz at lyx.org
Thu Aug 27 10:15:56 UTC 2020


commit 39caa7010008bbb32418d39d068f2fab65dbb748
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Aug 27 12:41:40 2020 +0200

    Clear info_ cache if format changes
---
 src/BiblioInfo.cpp           |   22 +++++++++++++++-------
 src/BiblioInfo.h             |    2 ++
 src/insets/InsetCitation.cpp |    4 +++-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 149b93b..7005519 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -488,8 +488,8 @@ docstring processRichtext(docstring const & str, bool richtext)
 //////////////////////////////////////////////////////////////////////
 
 BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
-	: is_bibtex_(true), bib_key_(key), num_bib_key_(0), entry_type_(type), info_(),
-	  modifier_(0)
+	: is_bibtex_(true), bib_key_(key), num_bib_key_(0), entry_type_(type),
+	  info_(), format_(), modifier_(0)
 {}
 
 
@@ -1000,6 +1000,19 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
 {
 	bool const richtext = ci.richtext;
 
+	CiteEngineType const engine_type = buf.params().citeEngineType();
+	DocumentClass const & dc = buf.params().documentClass();
+	docstring const & format = format_in.empty()? 
+				from_utf8(dc.getCiteFormat(engine_type, to_utf8(entry_type_)))
+			      : format_in;
+
+	if (format != format_) {
+		// clear caches since format changed
+		info_.clear();
+		info_richtext_.clear();
+		format_ = format;
+	}
+
 	if (!richtext && !info_.empty()) {
 		info_ = convertLaTeXCommands(processRichtext(info_, false));
 		return info_;
@@ -1013,11 +1026,6 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
 		return info_;
 	}
 
-	CiteEngineType const engine_type = buf.params().citeEngineType();
-	DocumentClass const & dc = buf.params().documentClass();
-	docstring const & format = format_in.empty()? 
-				from_utf8(dc.getCiteFormat(engine_type, to_utf8(entry_type_)))
-			      : format_in;
 	int counter = 0;
 	info_ = expandFormat(format, xrefs, counter, buf,
 		ci, false, false);
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index bc385f2..5a6f0d5 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -168,6 +168,8 @@ private:
 	mutable docstring info_;
 	/// a cache for getInfo(richtext = true)
 	mutable docstring info_richtext_;
+	/// cache for last format pattern
+	mutable docstring format_;
 	///
 	docstring cite_number_;
 	///
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index dc4bb2d..6f52fe2 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -215,7 +215,9 @@ void InsetCitation::openCitation()
 		titledata = subst(titledata, from_ascii(" and "), from_ascii(" "));
 		bi.getLocators(kvar, doi, url, file);
 		LYXERR(Debug::INSETS, "Locators: doi:" << doi << " url:"
-		        << url << " file:" << file << " title data:" << titledata);
+		        << url << " file:" << file << " title data:" << titledata
+		        << " citation search: " << lyxrc.citation_search
+		        << " citation search pattern: " << lyxrc.citation_search_pattern);
 		docstring locator;
 		if (!file.empty()) {
 			locator = file;


More information about the lyx-cvs mailing list