#include "ConverterCache.h"
#include "Format.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "Mover.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lyxtime.h"
#include "support/Package.h"
+#include "support/checksum.h"
#include "support/lassert.h"
-#include <boost/crc.hpp>
#include <algorithm>
#include <fstream>
namespace {
-unsigned long do_crc(string const & s)
-{
- boost::crc_32_type crc;
- crc = for_each(s.begin(), s.end(), crc);
- return crc.checksum();
-}
-
-
// FIXME THREAD
// This should be OK because it is only assigned during init()
static FileName cache_dir;
class CacheItem {
public:
- CacheItem() {}
+ CacheItem() : timestamp(0), checksum(0) {}
CacheItem(FileName const & orig_from, string const & to_format,
time_t t, unsigned long c)
: timestamp(t), checksum(c)
{
ostringstream os;
- os << setw(10) << setfill('0') << do_crc(orig_from.absFileName())
+ os << setw(10) << setfill('0')
+ << support::checksum(orig_from.absFileName())
<< '-' << to_format;
cache_name = FileName(addName(cache_dir.absFileName(), os.str()));
LYXERR(Debug::FILES, "Add file cache item " << orig_from
unsigned long checksum;
};
-}
+} // namespace
/** The cache contains one item per orig file and target format, so use a
FormatCache & format_cache = cache[orig_from_name];
if (format_cache.from_format.empty())
format_cache.from_format =
- formats.getFormatFromFile(orig_from_name);
+ // FIXME perf: This very expensive function is called on all
+ // cached files on opening. This slows LyX startup a lot. It
+ // would be better if this information was retrieved in a
+ // delayed fashion.
+ theFormats().getFormatFromFile(orig_from_name);
format_cache.cache[to_format] = item;
}
is.close();
string const & format)
{
if (!lyxrc.use_converter_cache)
- return 0;
+ return nullptr;
CacheType::iterator const it1 = cache.find(from);
if (it1 == cache.end())
- return 0;
+ return nullptr;
FormatCacheType & format_cache = it1->second.cache;
FormatCacheType::iterator const it2 = format_cache.find(format);
if (it2 == format_cache.end())
- return 0;
+ return nullptr;
return &(it2->second);
}
cache_dir = FileName(addName(package().user_support().absFileName(), "cache"));
if (!cache_dir.exists())
if (!cache_dir.createDirectory(0700)) {
+ // FIXME This should really be displayed as a message. But the GUI
+ // does not exist yet.
lyxerr << "Could not create cache directory `"
<< cache_dir << "'." << endl;
exit(EXIT_FAILURE);
void ConverterCache::writeIndex() const
{
- if (!lyxrc.use_converter_cache
+ if (!lyxrc.use_converter_cache
|| cache_dir.empty())
return;
pimpl_->writeIndex();
FormatCache & format_cache = pimpl_->cache[orig_from];
if (format_cache.from_format.empty())
format_cache.from_format =
- formats.getFormatFromFile(orig_from);
+ theFormats().getFormatFromFile(orig_from);
format_cache.cache[to_format] = new_item;
} else
LYXERR(Debug::FILES, "ConverterCache::add(" << orig_from << "):\n"