Kaydet (Commit) 58966e16 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Eike Rathke

sc: Simplify RemoveSubTotalsHandler using std::set

instead of std::vector.

Change-Id: I5927e061b5d2944cad68b96e313934738c63c321
Reviewed-on: https://gerrit.libreoffice.org/65400
Tested-by: Jenkins
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst cab88e6f
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include <svl/sharedstringpool.hxx> #include <svl/sharedstringpool.hxx>
#include <memory> #include <memory>
#include <set>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <mdds/flat_segment_tree.hpp> #include <mdds/flat_segment_tree.hpp>
...@@ -1864,25 +1865,14 @@ bool ScTable::TestRemoveSubTotals( const ScSubTotalParam& rParam ) ...@@ -1864,25 +1865,14 @@ bool ScTable::TestRemoveSubTotals( const ScSubTotalParam& rParam )
namespace { namespace {
class RemoveSubTotalsHandler struct RemoveSubTotalsHandler
{ {
std::vector<SCROW> maRemoved; std::set<SCROW> aRemoved;
public:
void operator() (size_t nRow, const ScFormulaCell* p) void operator() (size_t nRow, const ScFormulaCell* p)
{ {
if (p->IsSubTotal()) if (p->IsSubTotal())
maRemoved.push_back(nRow); aRemoved.insert(nRow);
}
void getRows(std::vector<SCROW>& rRows)
{
// Sort and remove duplicates.
std::sort(maRemoved.begin(), maRemoved.end());
std::vector<SCROW>::iterator it = std::unique(maRemoved.begin(), maRemoved.end());
maRemoved.erase(it, maRemoved.end());
maRemoved.swap(rRows);
} }
}; };
...@@ -1902,10 +1892,9 @@ void ScTable::RemoveSubTotals( ScSubTotalParam& rParam ) ...@@ -1902,10 +1892,9 @@ void ScTable::RemoveSubTotals( ScSubTotalParam& rParam )
sc::ParseFormula(rCells.begin(), rCells, nStartRow, nEndRow, aFunc); sc::ParseFormula(rCells.begin(), rCells, nStartRow, nEndRow, aFunc);
} }
std::vector<SCROW> aRows; auto& aRows = aFunc.aRemoved;
aFunc.getRows(aRows);
std::vector<SCROW>::reverse_iterator it = aRows.rbegin(), itEnd = aRows.rend(); auto it = aRows.rbegin(), itEnd = aRows.rend();
for (; it != itEnd; ++it) for (; it != itEnd; ++it)
{ {
SCROW nRow = *it; SCROW nRow = *it;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment