From: Richard Heck Date: Wed, 19 Oct 2016 21:22:58 +0000 (-0400) Subject: Simple cache for information on exportable formats, since we seem X-Git-Tag: 2.2.4~130 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=277529501483abb92fc678fc2ec9a2ce87daeb5e;p=features.git Simple cache for information on exportable formats, since we seem to access this information a lot. (cherry picked from commit 0b67e103e97a0c12fd18382152d762fc8d95dff1) --- diff --git a/src/BufferList.cpp b/src/BufferList.cpp index ff99a090f3..fd3f19de77 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -251,6 +251,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 690bf6a4e4..d4ae186a90 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 3f0f44aeff..8e799353d0 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -354,11 +354,17 @@ public: VSpace defskip; PDFOptions pdfoptions; LayoutFileIndex baseClass_; + /// Caching for exportableFormats, which seems to be slow. + std::vector exportableFormatList; + std::vector 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 @@ -2252,6 +2258,7 @@ void BufferParams::setDocumentClass(DocumentClassConstPtr tc) { // evil, but this function is evil doc_class_ = const_pointer_cast(tc); + invalidateConverterCache(); } @@ -2310,6 +2317,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(); @@ -2405,8 +2413,15 @@ bool BufferParams::isExportable(string const & format) const } -vector BufferParams::exportableFormats(bool only_viewable) const +vector const & BufferParams::exportableFormats(bool only_viewable) const { + vector & cached = only_viewable ? + pimpl_->viewableFormatList : pimpl_->exportableFormatList; + bool & valid = only_viewable ? + pimpl_->isViewCacheValid : pimpl_->isExportCacheValid; + if (valid) + return cached; + vector const backs = backends(); set excludes; if (useNonTeXFonts) { @@ -2421,15 +2436,16 @@ vector 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 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) { @@ -2526,7 +2542,7 @@ string BufferParams::getDefaultOutputFormat() const return default_output_format; if (isDocBook() || encoding().package() == Encoding::japanese) { - vector const formats = exportableFormats(true); + vector const & formats = exportableFormats(true); if (formats.empty()) return string(); // return the first we find @@ -3294,4 +3310,10 @@ vector 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 caae01dfec..b034b8801c 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -181,7 +181,7 @@ public: /// bool isExportable(std::string const & format) const; /// - std::vector exportableFormats(bool only_viewable) const; + std::vector const & exportableFormats(bool only_viewable) const; /// bool isExportableFormat(std::string const & format) const; /// the backends appropriate for use with this document. @@ -504,6 +504,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: /// @@ -552,7 +554,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 7696d0991f..71e3894598 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" @@ -1226,6 +1227,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 d9c4207c35..e5d821b601 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -3412,7 +3412,8 @@ void GuiPreferences::dispatchParams() theConverters() = converters_; theConverters().update(lyx::formats); theConverters().buildGraph(); - + theBufferList().invalidateConverterCache(); + theMovers() = movers_; vector::const_iterator it = colors_.begin();