commit 0b67e103e97a0c12fd18382152d762fc8d95dff1 Author: Richard Heck <rgh...@lyx.org> Date: Wed Oct 19 17:22:58 2016 -0400
Simple cache for information on exportable formats, since we seem to access this information a lot. --- src/BufferList.cpp | 9 +++++++++ src/BufferList.h | 2 ++ src/BufferParams.cpp | 34 ++++++++++++++++++++++++++++------ src/BufferParams.h | 6 ++++-- src/LyXRC.cpp | 2 ++ src/frontends/qt4/GuiPrefs.cpp | 3 ++- 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/BufferList.cpp b/src/BufferList.cpp index 0b76f13..b068f66 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -249,6 +249,15 @@ void BufferList::emergencyWriteAll() } +void BufferList::invalidateConverterCache() const +{ + BufferStorage::const_iterator it = bstore.begin(); + BufferStorage::const_iterator const en = bstore.end(); + for (; it != en; ++it) + (*it)->params().invalidateConverterCache(); +} + + bool BufferList::exists(FileName const & fname) const { return getBuffer(fname) != 0; diff --git a/src/BufferList.h b/src/BufferList.h index 690bf6a..d4ae186 100644 --- a/src/BufferList.h +++ b/src/BufferList.h @@ -124,6 +124,8 @@ public: void emergencyWriteAll(); /// FIXME void updateIncludedTeXfiles(std::string const &, OutputParams const &); + /// + void invalidateConverterCache() const; //@} private: diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 85a8cbb..72239d8 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -355,11 +355,17 @@ public: VSpace defskip; PDFOptions pdfoptions; LayoutFileIndex baseClass_; + /// Caching for exportableFormats, which seems to be slow. + std::vector<Format const *> exportableFormatList; + std::vector<Format const *> viewableFormatList; + bool isViewCacheValid; + bool isExportCacheValid; }; BufferParams::Impl::Impl() - : defskip(VSpace::MEDSKIP), baseClass_(string("")) + : defskip(VSpace::MEDSKIP), baseClass_(string("")), + isViewCacheValid(false), isExportCacheValid(false) { // set initial author // FIXME UNICODE @@ -2251,6 +2257,7 @@ void BufferParams::setDocumentClass(DocumentClassConstPtr tc) { // evil, but this function is evil doc_class_ = const_pointer_cast<DocumentClass>(tc); + invalidateConverterCache(); } @@ -2309,6 +2316,7 @@ void BufferParams::makeDocumentClass(bool const clone) if (!baseClass()) return; + invalidateConverterCache(); LayoutModuleList mods; LayoutModuleList::iterator it = layout_modules_.begin(); LayoutModuleList::iterator en = layout_modules_.end(); @@ -2395,8 +2403,15 @@ bool BufferParams::isExportable(string const & format) const } -vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const +vector<Format const *> const & BufferParams::exportableFormats(bool only_viewable) const { + vector<Format const *> & cached = only_viewable ? + pimpl_->viewableFormatList : pimpl_->exportableFormatList; + bool & valid = only_viewable ? + pimpl_->isViewCacheValid : pimpl_->isExportCacheValid; + if (valid) + return cached; + vector<string> const backs = backends(); set<string> excludes; if (useNonTeXFonts) { @@ -2411,15 +2426,16 @@ vector<Format const *> BufferParams::exportableFormats(bool only_viewable) const theConverters().getReachable(*it, only_viewable, false, excludes); result.insert(result.end(), r.begin(), r.end()); } - return result; + cached = result; + valid = true; + return cached; } bool BufferParams::isExportableFormat(string const & format) const { typedef vector<Format const *> Formats; - Formats formats; - formats = exportableFormats(true); + Formats const & formats = exportableFormats(true); Formats::const_iterator fit = formats.begin(); Formats::const_iterator end = formats.end(); for (; fit != end ; ++fit) { @@ -2516,7 +2532,7 @@ string BufferParams::getDefaultOutputFormat() const return default_output_format; if (isDocBook() || encoding().package() == Encoding::japanese) { - vector<Format const *> const formats = exportableFormats(true); + vector<Format const *> const & formats = exportableFormats(true); if (formats.empty()) return string(); // return the first we find @@ -3284,4 +3300,10 @@ vector<CitationStyle> BufferParams::citeStyles() const return styles; } +void BufferParams::invalidateConverterCache() const +{ + pimpl_->isExportCacheValid = false; + pimpl_->isViewCacheValid = false; +} + } // namespace lyx diff --git a/src/BufferParams.h b/src/BufferParams.h index 4efbe57..ea2cd5d 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -180,7 +180,7 @@ public: /// bool isExportable(std::string const & format) const; /// - std::vector<Format const *> exportableFormats(bool only_viewable) const; + std::vector<const Format *> const & exportableFormats(bool only_viewable) const; /// bool isExportableFormat(std::string const & format) const; /// the backends appropriate for use with this document. @@ -505,6 +505,8 @@ public: /// Return true if language could be set to lang, /// otherwise return false and do not change language bool setLanguage(std::string const & lang); + /// + void invalidateConverterCache() const; private: /// @@ -553,7 +555,7 @@ private: * mathdots, stackrel, stmaryrd and undertilde. */ PackageMap use_packages; - + /** Use the Pimpl idiom to hide those member variables that would otherwise * drag in other header files. */ diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index c3fef83..fe3b042 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -18,6 +18,7 @@ #include "LyXRC.h" +#include "BufferList.h" #include "ColorSet.h" #include "Converter.h" #include "FontEnums.h" @@ -1211,6 +1212,7 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) /// Update converters data-structures theConverters().update(formats); theConverters().buildGraph(); + theBufferList().invalidateConverterCache(); return ReadOK; } diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index dff16cc..d23c5fb 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -3447,7 +3447,8 @@ void GuiPreferences::dispatchParams() theConverters() = converters_; theConverters().update(lyx::formats); theConverters().buildGraph(); - + theBufferList().invalidateConverterCache(); + theMovers() = movers_; vector<string>::const_iterator it = colors_.begin();