Simple cache for information on exportable formats, since we seem

to access this information a lot.
This commit is contained in:
Richard Heck 2016-10-19 17:22:58 -04:00
parent 7cf12243b8
commit 0b67e103e9
6 changed files with 47 additions and 9 deletions

View File

@ -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;

View File

@ -124,6 +124,8 @@ public:
void emergencyWriteAll();
/// FIXME
void updateIncludedTeXfiles(std::string const &, OutputParams const &);
///
void invalidateConverterCache() const;
//@}
private:

View File

@ -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

View File

@ -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.
*/

View File

@ -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;
}

View File

@ -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();