From a0e266734d4e11aad20a31929822f2fca1fa56f3 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 25 Mar 2009 12:23:07 +0000 Subject: [PATCH] Cache the location of an InsetInclude's associated Buffer. Abdel says this will be OK. ;-) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28895 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetInclude.cpp | 27 ++++++++++++++++++++++----- src/insets/InsetInclude.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 1efd015cd0..d27fcb3cc6 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -162,7 +162,7 @@ InsetLabel * createLabel(docstring const & label_str) InsetInclude::InsetInclude(InsetCommandParams const & p) : InsetCommand(p, "include"), include_label(uniqueID()), preview_(new RenderMonitoredPreview(this)), failedtoload_(false), - set_label_(false), label_(0) + set_label_(false), label_(0), child_buffer_(0) { preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); @@ -176,7 +176,7 @@ InsetInclude::InsetInclude(InsetCommandParams const & p) InsetInclude::InsetInclude(InsetInclude const & other) : InsetCommand(other), include_label(other.include_label), preview_(new RenderMonitoredPreview(this)), failedtoload_(false), - set_label_(false), label_(0) + set_label_(false), label_(0), child_buffer_(0) { preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); @@ -230,6 +230,9 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_INSET_MODIFY: { + // It should be OK just to invalidate the cache is setParams() + // If not.... + // child_buffer_ = 0; InsetCommandParams p(INCLUDE_CODE); if (cmd.getArg(0) == "changetype") { InsetCommand::doDispatch(cur, cmd); @@ -311,6 +314,9 @@ bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetInclude::setParams(InsetCommandParams const & p) { + // invalidate the cache + child_buffer_ = 0; + InsetCommand::setParams(p); set_label_ = false; @@ -378,16 +384,25 @@ Buffer * InsetInclude::getChildBuffer(Buffer const & buffer) const Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const { - InsetCommandParams const & p = params(); + // Don't try to load it again if we failed before. if (failedtoload_) return 0; + // Use cached Buffer if possible. + if (child_buffer_ != 0) { + if (theBufferList().isLoaded(child_buffer_)) + return child_buffer_; + // Buffer vanished, so invalidate cache and try to reload. + child_buffer_ = 0; + } + + InsetCommandParams const & p = params(); if (isVerbatim(p) || isListings(p)) return 0; string const parent_filename = parent.absFileName(); - FileName const included_file = makeAbsPath(to_utf8(p["filename"]), - onlyPath(parent_filename)); + FileName const included_file = + makeAbsPath(to_utf8(p["filename"]), onlyPath(parent_filename)); if (!isLyXFilename(included_file.absFilename())) return 0; @@ -415,6 +430,8 @@ Buffer * InsetInclude::loadIfNeeded(Buffer const & parent) const } } child->setParent(&parent); + // Cache the child buffer. + child_buffer_ = child; return child; } diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 410b71270c..9708554693 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -134,6 +134,7 @@ private: mutable RenderButton button_; mutable docstring listings_label_; InsetLabel * label_; + mutable Buffer * child_buffer_; }; -- 2.39.2