sc/inc/column.hxx | 23 ----------------------- sc/inc/table.hxx | 27 +++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 27 deletions(-)
New commits: commit b5da114b67b29c91d16f2cb618cf30e7aa1b068d Author: Mike Kaganski <[email protected]> AuthorDate: Sat Mar 15 00:48:50 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sat Mar 15 10:58:19 2025 +0100 Move code applying functor to selection from ScColumnData to ScTable Helps in a following optimization work. Change-Id: I303432fe783ec2c7eb29196a5f6704cde24c8c1d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182930 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 22e3ad1e284c..0e334fdb0704 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -175,11 +175,6 @@ public: bool TestInsertRow( SCSIZE nSize ) const; void InsertRow( SCROW nStartRow, SCSIZE nSize ); void DeleteRow( SCROW nStartRow, SCSIZE nSize ); - - // Applies a function to the selected ranges. - // The function looks like - // ApplyDataFunc(ScColumnData& applyTo, SCROW nTop, SCROW nBottom) - template <typename ApplyDataFunc> void Apply(const ScMarkData&, SCCOL, ApplyDataFunc); }; // Use protected inheritance to prevent publishing some internal ScColumnData @@ -1070,22 +1065,4 @@ inline void ScColumnData::DeleteRow(SCROW nStartRow, SCSIZE nSize) pAttrArray->DeleteRow( nStartRow, nSize ); } -template <typename ApplyDataFunc> -void ScColumnData::Apply(const ScMarkData& rMark, SCCOL nCol, ApplyDataFunc apply) -{ - if (rMark.IsMultiMarked()) - { - ScMultiSelIter aMultiIter(rMark.GetMultiSelData(), nCol); - SCROW nTop, nBottom; - while (aMultiIter.Next(nTop, nBottom)) - apply(*this, nTop, nBottom); - } - else if (rMark.IsMarked()) - { - const ScRange& aRange = rMark.GetMarkArea(); - if (aRange.aStart.Col() <= nCol && nCol <= aRange.aEnd.Col()) - apply(*this, aRange.aStart.Row(), aRange.aEnd.Row()); - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 944b1a9e211e..3994436da521 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -155,6 +155,9 @@ private: const Iterator maEnd; }; +template <typename T> +concept ColumnDataApply = std::is_invocable_v<T, ScColumnData&, SCROW, SCROW>; + class ScTable { private: @@ -1458,11 +1461,14 @@ private: // as few columns as needed, and applies the rest to default column data. // The function looks like // ApplyDataFunc(ScColumnData& applyTo, SCROW nTop, SCROW nBottom) - template <typename ApplyDataFunc> + template <ColumnDataApply ApplyDataFunc> void ApplyWithAllocation(const ScMarkData&, ApplyDataFunc); + + // Applies a function to the selected ranges in a given column. + template <ColumnDataApply ApplyDataFunc> void Apply(const ScMarkData&, SCCOL, ApplyDataFunc); }; -template <typename ApplyDataFunc> +template <ColumnDataApply ApplyDataFunc> void ScTable::ApplyWithAllocation(const ScMarkData& rMark, ApplyDataFunc apply) { if (!rMark.GetTableSelect(nTab) || !(rMark.IsMultiMarked() || rMark.IsMarked())) @@ -1476,7 +1482,7 @@ void ScTable::ApplyWithAllocation(const ScMarkData& rMark, ApplyDataFunc apply) if (lastChangeCol >= 0) CreateColumnIfNotExists(lastChangeCol); - aDefaultColData.Apply(rMark, GetDoc().MaxCol(), apply); + Apply(rMark, GetDoc().MaxCol(), apply); } else // need to allocate all columns affected { @@ -1487,7 +1493,20 @@ void ScTable::ApplyWithAllocation(const ScMarkData& rMark, ApplyDataFunc apply) // The loop should go not to lastChangeCol, but over all columns, to apply to already allocated // in the "StartOfEqualColumns" range for (SCCOL i = 0; i < aCol.size(); i++) - aCol[i].Apply(rMark, i, apply); + Apply(rMark, i, apply); +} + +template <ColumnDataApply ApplyDataFunc> +void ScTable::Apply(const ScMarkData& rMark, SCCOL nCol, ApplyDataFunc apply) +{ + if (rMark.IsMultiMarked()) + { + ScColumnData& rCol = GetColumnData(nCol); + ScMultiSelIter aMultiIter(rMark.GetMultiSelData(), nCol); + SCROW nTop, nBottom; + while (aMultiIter.Next(nTop, nBottom)) + apply(rCol, nTop, nBottom); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
