]> git.lyx.org Git - features.git/commitdiff
Cache the location of an InsetInclude's associated Buffer.
authorRichard Heck <rgheck@comcast.net>
Wed, 25 Mar 2009 12:23:07 +0000 (12:23 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 25 Mar 2009 12:23:07 +0000 (12:23 +0000)
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
src/insets/InsetInclude.h

index 1efd015cd0839c2fe2f6ed361574d2f79d2e8af2..d27fcb3cc6a58fa48660ee6e96ddb695ea01b6e7 100644 (file)
@@ -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;
 }
 
index 410b71270c99fd20ae433273a6667de494af1261..97085546938c95a001ec1ccedab9c325f09ab609 100644 (file)
@@ -134,6 +134,7 @@ private:
        mutable RenderButton button_;
        mutable docstring listings_label_;
        InsetLabel * label_;
+       mutable Buffer * child_buffer_;
 };