]> git.lyx.org Git - features.git/commitdiff
Backport fix for #7923: Don't clone all the children on autosave.
authorRichard Heck <rgheck@comcast.net>
Wed, 21 Dec 2011 15:08:26 +0000 (15:08 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 21 Dec 2011 15:08:26 +0000 (15:08 +0000)
We split Buffer::clone() into various routines that know whether
to clone the children.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40536 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiView.cpp
status.20x

index 7a086808076122a21fa90553573236f1cd805c96..cf2646caffdb119f46725d78b18228b602505a21 100644 (file)
@@ -459,13 +459,13 @@ Buffer::~Buffer()
 }
 
 
-Buffer * Buffer::clone() const
+Buffer * Buffer::cloneFromMaster() const
 {
        BufferMap bufmap;
        cloned_buffers.push_back(new CloneList());
        CloneList * clones = cloned_buffers.back();
 
-       masterBuffer()->clone(bufmap, clones);
+       masterBuffer()->cloneWithChildren(bufmap, clones);
 
        // make sure we got cloned
        BufferMap::const_iterator bit = bufmap.find(this);
@@ -476,7 +476,7 @@ Buffer * Buffer::clone() const
 }
 
 
-void Buffer::clone(BufferMap & bufmap, CloneList * clones) const
+void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList * clones) const
 {
        // have we already been cloned?
        if (bufmap.find(this) != bufmap.end())
@@ -499,10 +499,10 @@ void Buffer::clone(BufferMap & bufmap, CloneList * clones) const
                dit.setBuffer(buffer_clone);
                Buffer * child = const_cast<Buffer *>(it->second.second);
 
-               child->clone(bufmap, clones);
-               BufferMap::iterator it = bufmap.find(child);
-               LASSERT(it != bufmap.end(), continue);
-               Buffer * child_clone = it->second;
+               child->cloneWithChildren(bufmap, clones);
+               BufferMap::iterator const bit = bufmap.find(child);
+               LASSERT(bit != bufmap.end(), continue);
+               Buffer * child_clone = bit->second;
 
                Inset * inset = dit.nextInset();
                LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
@@ -517,6 +517,18 @@ void Buffer::clone(BufferMap & bufmap, CloneList * clones) const
 }
 
 
+Buffer * Buffer::cloneBufferOnly() const {
+       cloned_buffers.push_back(new CloneList());
+       CloneList * clones = cloned_buffers.back();
+       Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this);
+       clones->insert(buffer_clone);
+       buffer_clone->d->clone_list_ = clones;
+       // we won't be cloning the children
+       buffer_clone->d->children_positions.clear();
+       return buffer_clone;
+}
+
+
 bool Buffer::isClone() const
 {
        return d->cloned_buffer_;
index d230ec158eb2685678b57df77d4e7401d048d6fc..a0ac56b1b52e18d8d7e9761b496593e5f2eb53b6 100644 (file)
@@ -152,8 +152,11 @@ public:
        /// Destructor
        ~Buffer();
 
-       ///
-       Buffer * clone() const;
+       /// Clones the entire structure of which this Buffer is part, starting
+       /// with the master and cloning all the children, too.
+       Buffer * cloneFromMaster() const;
+       /// Just clones this single Buffer. For autosave.
+       Buffer * cloneBufferOnly() const;
        ///
        bool isClone() const;
 
@@ -216,7 +219,7 @@ private:
        ///
        typedef std::map<Buffer const *, Buffer *> BufferMap;
        ///
-       void clone(BufferMap &, CloneList *) const;
+       void cloneWithChildren(BufferMap &, CloneList *) const;
        /// save timestamp and checksum of the given file.
        void saveCheckSum() const;      
        /// read a new file
index 81354f1949d776cd90fdabea96963694275c8f2f..58b71c41cd67db66fc6c5f2e308f58199beac3e4 100644 (file)
@@ -1558,7 +1558,7 @@ void GuiView::autoSave()
 #if (QT_VERSION >= 0x040400)
        GuiViewPrivate::busyBuffers.insert(buffer);
        QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::autosaveAndDestroy,
-               buffer, buffer->clone());
+               buffer, buffer->cloneBufferOnly());
        d.autosave_watcher_.setFuture(f);
 #else
        buffer->autoSave();
@@ -3057,7 +3057,7 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
        QFuture<docstring> f = QtConcurrent::run(
                                asyncFunc,
                                used_buffer,
-                               used_buffer->clone(),
+                               used_buffer->cloneFromMaster(),
                                format);
        setPreviewFuture(f);
        last_export_format = used_buffer->params().bufferFormat();
index aed1009ea0216f5a244ab230803b2ed13cf18e0f..8969def0c6d2b6a2285916a13fe7524a880cacba 100644 (file)
@@ -32,6 +32,8 @@ What's new
 - New layout and template file for articles in the Journal of the Acoustical
   Society of America (JASA). 
 
+- Speed up autosave a bit by not cloning child documents (bug 7923).
+
 
 * TEX2LYX IMPROVEMENTS