Sort ptr_vector using its own sort() method.
This also fixes memory leak via nested calls of release(). Change-Id: I3ba90901366319bb3ee870903130042b375f733c
This commit is contained in:
@@ -1509,6 +1509,23 @@ void SvTreeList::Resort()
|
|||||||
Broadcast( LISTACTION_RESORTED );
|
Broadcast( LISTACTION_RESORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class SortComparator : public std::binary_function<SvTreeListEntry,SvTreeListEntry,bool>
|
||||||
|
{
|
||||||
|
SvTreeList& mrList;
|
||||||
|
public:
|
||||||
|
|
||||||
|
SortComparator( SvTreeList& rList ) : mrList(rList) {}
|
||||||
|
|
||||||
|
bool operator() ( const SvTreeListEntry& pLeft, const SvTreeListEntry& pRight ) const
|
||||||
|
{
|
||||||
|
return mrList.Compare(&pLeft, &pRight) < 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SvTreeList::ResortChildren( SvTreeListEntry* pParent )
|
void SvTreeList::ResortChildren( SvTreeListEntry* pParent )
|
||||||
{
|
{
|
||||||
DBG_ASSERT(pParent,"Parent not set");
|
DBG_ASSERT(pParent,"Parent not set");
|
||||||
@@ -1516,38 +1533,18 @@ void SvTreeList::ResortChildren( SvTreeListEntry* pParent )
|
|||||||
if (pParent->maChildren.empty())
|
if (pParent->maChildren.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: Re-implement this using ptr_vector's sort method.
|
SortComparator aComp(*this);
|
||||||
|
pParent->maChildren.sort(aComp);
|
||||||
|
|
||||||
std::vector<SvTreeListEntry*> aStore; // Temporarily store entries.
|
// Recursively sort child entries.
|
||||||
aStore.reserve(pParent->maChildren.size());
|
SvTreeListEntries::iterator it = pParent->maChildren.begin(), itEnd = pParent->maChildren.end();
|
||||||
{
|
|
||||||
SvTreeListEntries::iterator it = pParent->maChildren.begin(), itEnd = pParent->maChildren.end();
|
|
||||||
for (; it != itEnd; ++it)
|
|
||||||
{
|
|
||||||
SvTreeListEntry* p = &(*it);
|
|
||||||
aStore.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pParent->maChildren.release().release(); // Release all stored entries and empty the container.
|
|
||||||
|
|
||||||
std::vector<SvTreeListEntry*>::iterator it = aStore.begin(), itEnd = aStore.end();
|
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
{
|
{
|
||||||
SvTreeListEntry* p = *it;
|
SvTreeListEntry& r = *it;
|
||||||
sal_uLong nListPos = TREELIST_APPEND;
|
if (!r.maChildren.empty())
|
||||||
GetInsertionPos(p, pParent, nListPos);
|
ResortChildren(&r);
|
||||||
if (nListPos < pParent->maChildren.size())
|
|
||||||
{
|
|
||||||
SvTreeListEntries::iterator itPos = pParent->maChildren.begin();
|
|
||||||
std::advance(itPos, nListPos);
|
|
||||||
pParent->maChildren.insert(itPos, p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
pParent->maChildren.push_back(p);
|
|
||||||
if (!p->maChildren.empty())
|
|
||||||
// Recursively sort child entries.
|
|
||||||
ResortChildren(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetListPositions(pParent->maChildren); // correct list position in target list
|
SetListPositions(pParent->maChildren); // correct list position in target list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user