summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-05-15 09:55:49 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-05-15 09:58:01 -0400
commitb79b8d2c613588f6a0175160c7f0a1161ea84b35 (patch)
tree7842c47b2a968fa62086826fa565ffe358cae877 /svtools
parenta994503f23ae3f1d88afbdb8146cdc93453fdc85 (diff)
Sort ptr_vector using its own sort() method.
This also fixes memory leak via nested calls of release(). Change-Id: I3ba90901366319bb3ee870903130042b375f733c
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/contnr/treelist.cxx53
1 files changed, 25 insertions, 28 deletions
diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx
index 0d92afd58fe7..a64c1e045051 100644
--- a/svtools/source/contnr/treelist.cxx
+++ b/svtools/source/contnr/treelist.cxx
@@ -1509,6 +1509,23 @@ void SvTreeList::Resort()
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 )
{
DBG_ASSERT(pParent,"Parent not set");
@@ -1516,38 +1533,18 @@ void SvTreeList::ResortChildren( SvTreeListEntry* pParent )
if (pParent->maChildren.empty())
return;
- // TODO: Re-implement this using ptr_vector's sort method.
-
- std::vector<SvTreeListEntry*> aStore; // Temporarily store entries.
- aStore.reserve(pParent->maChildren.size());
- {
- 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.
+ SortComparator aComp(*this);
+ pParent->maChildren.sort(aComp);
- std::vector<SvTreeListEntry*>::iterator it = aStore.begin(), itEnd = aStore.end();
+ // Recursively sort child entries.
+ SvTreeListEntries::iterator it = pParent->maChildren.begin(), itEnd = pParent->maChildren.end();
for (; it != itEnd; ++it)
{
- SvTreeListEntry* p = *it;
- sal_uLong nListPos = TREELIST_APPEND;
- GetInsertionPos(p, pParent, nListPos);
- 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);
+ SvTreeListEntry& r = *it;
+ if (!r.maChildren.empty())
+ ResortChildren(&r);
}
+
SetListPositions(pParent->maChildren); // correct list position in target list
}