This patch adds a cache for FileName::isZipped, because the file has to be read to get that information. The plan is to eventually replace most filename variables of type string with variables of type FileName. That would mean less checks like BOOST_ASSERT(absolutePath(file_in)); And of course easy acces to mangledFilename. This is also the first step of my promised patch to make preview of graphic files with a ' in the name possible, because I will reusse copyToDirIfNeeded() for that.
This will go in soon unless somebody objects. Georg Log: make FileName::isZipped more efficient by caching previous results * src/insets/insetgraphics.C (copyToDirIfNeeded): replace file_in and zipped arguments with a FileName argument (InsetGraphics::prepareFile): adjust call of copyToDirIfNeeded * src/support/filename.C (FileName::FileName): set zipped_valid_ (FileName::set): ditto (FileName::erase): ditto (isZipped): use zipped_ * src/support/filename.[Ch] (zipped_): new cache for isZipped() (zipped_valid_): new, tell whether zipped_ is valid
Index: src/insets/insetgraphics.C =================================================================== --- src/insets/insetgraphics.C (Revision 14367) +++ src/insets/insetgraphics.C (Arbeitskopie) @@ -484,25 +484,24 @@ copyFileIfNeeded(string const & file_in, std::pair<CopyStatus, string> const -copyToDirIfNeeded(string const & file_in, string const & dir, bool zipped) +copyToDirIfNeeded(FileName const & file, string const & dir) { using support::rtrim; - BOOST_ASSERT(absolutePath(file_in)); - + string const file_in = file.absFilename(); string const only_path = support::onlyPath(file_in); if (rtrim(support::onlyPath(file_in) , "/") == rtrim(dir, "/")) return std::make_pair(IDENTICAL_PATHS, file_in); - string mangled = FileName(file_in).mangledFilename(); - if (zipped) { + string mangled = file.mangledFilename(); + if (file.isZipped()) { // We need to change _eps.gz to .eps.gz. The mangled name is // still unique because of the counter in mangledFilename(). // We can't just call mangledFilename() with the zip // extension removed, because base.eps and base.eps.gz may // have different content but would get the same mangled // name in this case. - string const base = removeExtension(unzippedFileName(file_in)); + string const base = removeExtension(file.unzippedFilename()); string::size_type const ext_len = file_in.length() - base.length(); mangled[mangled.length() - ext_len] = '.'; } @@ -563,11 +562,6 @@ string const InsetGraphics::prepareFile( if (runparams.dryrun) return stripExtensionIfPossible(rel_file); - // If the file is compressed and we have specified that it - // should not be uncompressed, then just return its name and - // let LaTeX do the rest! - bool const zipped = params().filename.isZipped(); - // temp_file will contain the file for LaTeX to act on if, for example, // we move it to a temp dir or uncompress it. string temp_file = orig_file; @@ -590,7 +584,7 @@ string const InsetGraphics::prepareFile( CopyStatus status; boost::tie(status, temp_file) = - copyToDirIfNeeded(orig_file, temp_path, zipped); + copyToDirIfNeeded(params().filename, temp_path); if (status == FAILURE) return orig_file; @@ -606,7 +600,10 @@ string const InsetGraphics::prepareFile( string const tex_format = (runparams.flavor == OutputParams::LATEX) ? "latex" : "pdflatex"; - if (zipped) { + // If the file is compressed and we have specified that it + // should not be uncompressed, then just return its name and + // let LaTeX do the rest! + if (params().filename.isZipped()) { if (params().noUnzip) { // We don't know whether latex can actually handle // this file, but we can't check, because that would Index: src/graphics/GraphicsCacheItem.C =================================================================== --- src/graphics/GraphicsCacheItem.C (Revision 14367) +++ src/graphics/GraphicsCacheItem.C (Arbeitskopie) @@ -36,7 +36,6 @@ using support::onlyFilename; using support::tempName; using support::unlink; using support::unzipFile; -using support::unzippedFileName; using support::zippedFile; using std::endl; Index: src/support/filename.C =================================================================== --- src/support/filename.C (Revision 14367) +++ src/support/filename.C (Arbeitskopie) @@ -36,7 +36,7 @@ FileName::FileName() FileName::FileName(string const & abs_filename, bool save_abs) - : name_(abs_filename), save_abs_path_(save_abs) + : name_(abs_filename), save_abs_path_(save_abs), zipped_valid_(false) { BOOST_ASSERT(absolutePath(name_)); } @@ -46,12 +46,14 @@ void FileName::set(string const & name, { save_abs_path_ = absolutePath(name); name_ = save_abs_path_ ? name : makeAbsPath(name, buffer_path); + zipped_valid_ = false; } void FileName::erase() { name_.erase(); + zipped_valid_ = false; } @@ -125,7 +127,11 @@ string const FileName::mangledFilename(s bool FileName::isZipped() const { - return zippedFile(name_); + if (!zipped_valid_) { + zipped_ = zippedFile(name_); + zipped_valid_ = true; + } + return zipped_; } Index: src/support/filename.h =================================================================== --- src/support/filename.h (Revision 14367) +++ src/support/filename.h (Arbeitskopie) @@ -75,6 +75,10 @@ public: private: std::string name_; bool save_abs_path_; + /// Cache for isZipped() because zippedFile() is expensive + mutable bool zipped_; + /// Is zipped_ valid? + mutable bool zipped_valid_; };