]> git.lyx.org Git - features.git/commitdiff
Simple cache for information on exportable formats, since we seem
authorRichard Heck <rgheck@lyx.org>
Wed, 19 Oct 2016 21:22:58 +0000 (17:22 -0400)
committerRichard Heck <rgheck@lyx.org>
Thu, 25 May 2017 01:39:22 +0000 (21:39 -0400)
to access this information a lot.

(cherry picked from commit 0b67e103e97a0c12fd18382152d762fc8d95dff1)

src/BufferList.cpp
src/BufferList.h
src/BufferParams.cpp
src/BufferParams.h
src/LyXRC.cpp
src/frontends/qt4/GuiPrefs.cpp

index ff99a090f35ea08ad398bbb8eabaf1ca92ef9238..fd3f19de77c6f65dbeff18e0852105a9d5650c30 100644 (file)
@@ -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;
index 690bf6a4e4a8a905970c85ff2bd8bdf3ca347bad..d4ae186a907991fbd86be35be04be1b01b1ec232 100644 (file)
@@ -124,6 +124,8 @@ public:
        void emergencyWriteAll();
        /// FIXME
        void updateIncludedTeXfiles(std::string const &, OutputParams const &);
+       ///
+       void invalidateConverterCache() const;
        //@}
 
 private:
index 3f0f44aeff5956fe659c638593017700bf5008a2..8e799353d0ff523d829a903e8fb9115397b647eb 100644 (file)
@@ -354,11 +354,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
@@ -2252,6 +2258,7 @@ void BufferParams::setDocumentClass(DocumentClassConstPtr tc)
 {
        // evil, but this function is evil
        doc_class_ = const_pointer_cast<DocumentClass>(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<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) {
@@ -2421,15 +2436,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) {
@@ -2526,7 +2542,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
@@ -3294,4 +3310,10 @@ vector<CitationStyle> BufferParams::citeStyles() const
        return styles;
 }
 
+void BufferParams::invalidateConverterCache() const
+{
+       pimpl_->isExportCacheValid = false;
+       pimpl_->isViewCacheValid = false;
+}
+
 } // namespace lyx
index caae01dfec15535e847429326491d15cfbc5e7df..b034b8801ca58cac968425f621285e9f2abaec33 100644 (file)
@@ -181,7 +181,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.
@@ -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.
         */
index 7696d0991fb2502d888c0183ee49d63c84605734..71e389459891d0c10d6a8532c60bb956869068d5 100644 (file)
@@ -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;
 }
index d9c4207c35cd985e17c273246be3837b4187f9b0..e5d821b60189ed2d1011a613f1a0b49e956c162e 100644 (file)
@@ -3412,7 +3412,8 @@ void GuiPreferences::dispatchParams()
        theConverters() = converters_;
        theConverters().update(lyx::formats);
        theConverters().buildGraph();
-
+       theBufferList().invalidateConverterCache();
+       
        theMovers() = movers_;
 
        vector<string>::const_iterator it = colors_.begin();