tdf#148143: Reset the position hint when flat_segment_tree gets copied
std::optional stores the wrapped object as part of its memory footprint,
and when it gets copied, it copy-constructs the wrapped object too. We
need to be aware of this when using std::optional inside std::vector
which may reallocate its internal buffer and copy the stored elements.
Change-Id: Ib8fab1295388ae2ee9ef3d044943ac3c2bc8e529
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148152
Tested-by: Jenkins
Reviewed-by: Kohei Yoshida <kohei@libreoffice.org>
(cherry picked from commit c4187189060a104cf36d8a8c9b2958b8c28cde0b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148233
diff --git a/sc/inc/columnspanset.hxx b/sc/inc/columnspanset.hxx
index d8cfc41..5a3dc76 100644
--- a/sc/inc/columnspanset.hxx
+++ b/sc/inc/columnspanset.hxx
@@ -58,6 +58,7 @@ private:
ColumnSpansType::const_iterator miPos;
ColumnType(SCROW nStart, SCROW nEnd, bool bInit);
ColumnType(const ColumnType& rOther);
};
typedef std::vector<std::optional<ColumnType>> TableType;
diff --git a/sc/source/core/data/columnspanset.cxx b/sc/source/core/data/columnspanset.cxx
index eb09ea2..bec9c8a 100644
--- a/sc/source/core/data/columnspanset.cxx
+++ b/sc/source/core/data/columnspanset.cxx
@@ -53,6 +53,9 @@ ColRowSpan::ColRowSpan(SCCOLROW nStart, SCCOLROW nEnd) : mnStart(nStart), mnEnd(
ColumnSpanSet::ColumnType::ColumnType(SCROW nStart, SCROW nEnd, bool bInit) :
maSpans(nStart, nEnd+1, bInit), miPos(maSpans.begin()) {}
ColumnSpanSet::ColumnType::ColumnType(const ColumnType& rOther) :
maSpans(rOther.maSpans), miPos(maSpans.begin()) {} // NB: copying maSpans invalidates miPos - reset it
ColumnSpanSet::Action::~Action() {}
void ColumnSpanSet::Action::startColumn(SCTAB /*nTab*/, SCCOL /*nCol*/) {}
@@ -142,6 +145,7 @@ void ColumnSpanSet::scan(
ColumnNonEmptyRangesScanner aScanner(rCol.maSpans, bVal);
ParseBlock(rSrcCells.begin(), rSrcCells, aScanner, nRow1, nRow2);
rCol.miPos = rCol.maSpans.begin();
}
}