mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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.
This commit is contained in:
parent
01fc62b78e
commit
e8ffb0c97a
@ -517,8 +517,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()) {
|
||||
|
@ -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>
|
||||
@ -364,31 +386,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();
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user