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 e8ffb0c97a)
This commit is contained in:
Richard Heck 2016-01-05 09:52:18 -05:00
parent ce7782be5b
commit 3799213096
3 changed files with 33 additions and 31 deletions

View File

@ -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()) {

View File

@ -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();

View File

@ -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();