sc/source/core/data/column3.cxx | 1 sc/source/core/data/column4.cxx | 59 ++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 26 deletions(-)
New commits: commit 5234ef71c7459506236d4d0dfe7beb5f00d8cc41 Author: Kohei Yoshida <ko...@libreoffice.org> AuthorDate: Mon Feb 26 22:59:32 2024 -0500 Commit: Kohei Yoshida <ko...@libreoffice.org> CommitDate: Wed Feb 28 02:31:27 2024 +0100 Make the code tidier & stop event handling during destruction This is a follow-up to 25ffb54c6d8a5b52dca6b782282962766e7791de. Change-Id: Ifc87323dd5085cdac08efac5fd9d22ae8b94d641 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163997 Tested-by: Jenkins Reviewed-by: Kohei Yoshida <ko...@libreoffice.org> diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 3481abfe8e9e..e01d6312506f 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -238,6 +238,7 @@ void ScColumn::Delete( SCROW nRow ) void ScColumn::FreeAll() { maCells.event_handler().stop(); + maCellNotes.event_handler().stop(); auto maxRowCount = GetDoc().GetMaxRowCount(); // Keep a logical empty range of 0-rDoc.MaxRow() at all times. diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index bd9bba3df1f4..7b1299d7bae6 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -2212,39 +2212,46 @@ void ScColumn::RestoreFromCache(SvStream& rStrm) void ScColumn::CheckIntegrity() const { - const ScColumn* pColTest = maCells.event_handler().getColumn(); + auto checkEventHandlerColumnRef = [this](const auto& rStore, std::string_view pStoreName) + { + if (const ScColumn* pColTest = rStore.event_handler().getColumn(); pColTest != this) + { + std::ostringstream os; + os << pStoreName << "'s event handler references wrong column instance (this=" << this + << "; stored=" << pColTest << ")"; + throw std::runtime_error(os.str()); + } + }; - if (pColTest != this) + auto countBlocks = [](const auto& rStore, mdds::mtv::element_t nBlockType) { - std::ostringstream os; - os << "cell store's event handler references wrong column instance (this=" << this - << "; stored=" << pColTest << ")"; - throw std::runtime_error(os.str()); - } + std::size_t nCount = std::count_if(rStore.cbegin(), rStore.cend(), + [nBlockType](const auto& blk) { return blk.type == nBlockType; } + ); - size_t nCount = std::count_if(maCells.cbegin(), maCells.cend(), - [](const auto& blk) { return blk.type == sc::element_type_formula; } - ); + return nCount; + }; - if (mnBlkCountFormula != nCount) + auto checkCachedBlockCount = [countBlocks]( + const auto& rStore, mdds::mtv::element_t nBlockType, std::size_t nCachedBlkCount, + std::string_view pName) { - std::ostringstream os; - os << "incorrect cached formula block count (expected=" << nCount << "; actual=" - << mnBlkCountFormula << ")"; - throw std::runtime_error(os.str()); - } + std::size_t nCount = countBlocks(rStore, nBlockType); - nCount = std::count_if(maCellNotes.cbegin(), maCellNotes.cend(), - [](const auto& blk) { return blk.type == sc::element_type_cellnote; } - ); + if (nCachedBlkCount != nCount) + { + std::ostringstream os; + os << "incorrect cached " << pName << " block count (expected=" << nCount << "; actual=" + << nCachedBlkCount << ")"; + throw std::runtime_error(os.str()); + } + }; - if (mnBlkCountCellNotes != nCount) - { - std::ostringstream os; - os << "incorrect cached cell note block count (expected=" << nCount << "; actual=" - << mnBlkCountCellNotes << ")"; - throw std::runtime_error(os.str()); - } + checkEventHandlerColumnRef(maCells, "cell store"); + checkEventHandlerColumnRef(maCellNotes, "cell-note store"); + + checkCachedBlockCount(maCells, sc::element_type_formula, mnBlkCountFormula, "formula"); + checkCachedBlockCount(maCellNotes, sc::element_type_cellnote, mnBlkCountCellNotes, "cell note"); } void ScColumn::CollectBroadcasterState(sc::BroadcasterState& rState) const