commit 37992130966569d7216e0853e40582765c05a56e
Author: Richard Heck <[email protected]>
Date: Tue Jan 5 09:52:18 2016 -0500
Rewrite the BufferList::releaseChild method so that it only checks
whether a given child Buffer is also a child of some other parent.
Then do the releasing or resetting where this method is called.
There should be no change of behavior with this patch.
(cherry picked from commit e8ffb0c97aa7c5a27dd3fcfc79a4ce13d8701762)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index a78e9e3..056b9cc 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -486,8 +486,12 @@ Buffer::~Buffer()
Impl::BufferPositionMap::iterator end =
d->children_positions.end();
for (; it != end; ++it) {
Buffer * child = const_cast<Buffer *>(it->first);
- if (theBufferList().isLoaded(child))
- theBufferList().releaseChild(this, child);
+ if (theBufferList().isLoaded(child)) {
+ if (theBufferList().isOthersChild(this, child))
+ child->setParent(0);
+ else
+ theBufferList().release(child);
+ }
}
if (!isClean()) {
diff --git a/src/BufferList.cpp b/src/BufferList.cpp
index c253282..3b578ae 100644
--- a/src/BufferList.cpp
+++ b/src/BufferList.cpp
@@ -267,6 +267,28 @@ bool BufferList::exists(FileName const & fname) const
}
+bool BufferList::isOthersChild(Buffer * parent, Buffer * child)
+{
+ LASSERT(parent, return false);
+ LASSERT(child, return false);
+ LASSERT(parent->isChild(child), return false);
+
+ // Does child document have a different parent?
+ Buffer const * parent_ = child->parent();
+ if (parent_ && parent_ != parent)
+ return true;
+
+ BufferStorage::iterator it = bstore.begin();
+ BufferStorage::iterator end = bstore.end();
+ for (; it != end; ++it) {
+ Buffer * buf = *it;
+ if (buf != parent && buf->isChild(child))
+ return true;
+ }
+ return false;
+}
+
+
namespace {
struct equivalent_to : public binary_function<FileName, FileName, bool>
@@ -355,31 +377,6 @@ int BufferList::bufferNum(FileName const & fname) const
}
-bool BufferList::releaseChild(Buffer * parent, Buffer * child)
-{
- LASSERT(parent, return false);
- LASSERT(child, return false);
- LASSERT(parent->isChild(child), return false);
-
- // Child document has a different parent, don't close it.
- Buffer const * parent_ = child->parent();
- if (parent_ && parent_ != parent)
- return false;
-
- BufferStorage::iterator it = bstore.begin();
- BufferStorage::iterator end = bstore.end();
- for (; it != end; ++it) {
- Buffer * buf = *it;
- if (buf != parent && buf->isChild(child)) {
- child->setParent(0);
- return false;
- }
- }
- release(child);
- return true;
-}
-
-
void BufferList::changed(bool update_metrics) const
{
BufferStorage::const_iterator it = bstore.begin();
diff --git a/src/BufferList.h b/src/BufferList.h
index 4f9cb95..9259f36 100644
--- a/src/BufferList.h
+++ b/src/BufferList.h
@@ -55,13 +55,14 @@ public:
/// \return 0 if the Buffer creation is not possible for whatever
reason.
Buffer * newInternalBuffer(std::string const & s);
+ /// Is child a child of some Buffer other than parent?
+ /// NOTE: child must be a child of parent, and both must be non-null.
+ /// Otherwise we assert.
+ bool isOthersChild(Buffer * parent, Buffer * child);
+
/// delete a buffer
void release(Buffer * b);
- /// Release \p child if it really is a child and is not used elsewhere.
- /// \return true is the file was closed.
- bool releaseChild(Buffer * parent, Buffer * child);
-
/// Close all open buffers.
void closeAll();