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>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user