mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-24 02:35:20 +00:00
Simple cache for information on exportable formats, since we seem
to access this information a lot.
(cherry picked from commit 0b67e103e9
)
This commit is contained in:
parent
d2b6520783
commit
2775295014
@ -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;
|
||||
|
@ -124,6 +124,8 @@ public:
|
||||
void emergencyWriteAll();
|
||||
/// FIXME
|
||||
void updateIncludedTeXfiles(std::string const &, OutputParams const &);
|
||||
///
|
||||
void invalidateConverterCache() const;
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
///
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -3412,6 +3412,7 @@ void GuiPreferences::dispatchParams()
|
||||
theConverters() = converters_;
|
||||
theConverters().update(lyx::formats);
|
||||
theConverters().buildGraph();
|
||||
theBufferList().invalidateConverterCache();
|
||||
|
||||
theMovers() = movers_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user