diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp index ec45e35484d..c0616a49c8a 100644 --- a/src/plugins/diffeditor/diffeditordocument.cpp +++ b/src/plugins/diffeditor/diffeditordocument.cpp @@ -58,8 +58,8 @@ DiffEditorController *DiffEditorDocument::controller() const static void appendRow(ChunkData *chunk, const RowData &row) { - const bool isSeparator = row.leftLine.textLineType == TextLineData::Separator - && row.rightLine.textLineType == TextLineData::Separator; + const bool isSeparator = row.line[LeftSide].textLineType == TextLineData::Separator + && row.line[RightSide].textLineType == TextLineData::Separator; if (!isSeparator) chunk->rows.append(row); } @@ -83,30 +83,30 @@ ChunkData DiffEditorDocument::filterChunk(const ChunkData &data, } else if (isLeftSelected) { RowData newRow = row; - row.rightLine = TextLineData(TextLineData::Separator); + row.line[RightSide] = TextLineData(TextLineData::Separator); appendRow(&chunk, row); if (revert) { - newRow.leftLine = newRow.rightLine; + newRow.line[LeftSide] = newRow.line[RightSide]; newRow.equal = true; appendRow(&chunk, newRow); } } else { // isRightSelected if (!revert) { RowData newRow = row; - newRow.rightLine = newRow.leftLine; + newRow.line[RightSide] = newRow.line[LeftSide]; newRow.equal = true; appendRow(&chunk, newRow); } - row.leftLine = TextLineData(TextLineData::Separator); + row.line[LeftSide] = TextLineData(TextLineData::Separator); appendRow(&chunk, row); } } else { if (revert) - row.leftLine = row.rightLine; + row.line[LeftSide] = row.line[RightSide]; else - row.rightLine = row.leftLine; + row.line[RightSide] = row.line[LeftSide]; row.equal = true; appendRow(&chunk, row); } diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp index 7fb8abcbac6..4d087265602 100644 --- a/src/plugins/diffeditor/diffeditorplugin.cpp +++ b/src/plugins/diffeditor/diffeditorplugin.cpp @@ -851,10 +851,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch() const RowData &sourceRowData = sourceChunk.rows.at(k); const RowData &resultRowData = resultChunkData.rows.at(k); QCOMPARE(resultRowData.equal, sourceRowData.equal); - QCOMPARE(resultRowData.leftLine.text, sourceRowData.leftLine.text); - QCOMPARE(resultRowData.leftLine.textLineType, sourceRowData.leftLine.textLineType); - QCOMPARE(resultRowData.rightLine.text, sourceRowData.rightLine.text); - QCOMPARE(resultRowData.rightLine.textLineType, sourceRowData.rightLine.textLineType); + QCOMPARE(resultRowData.line[LeftSide].text, sourceRowData.line[LeftSide].text); + QCOMPARE(resultRowData.line[LeftSide].textLineType, sourceRowData.line[LeftSide].textLineType); + QCOMPARE(resultRowData.line[RightSide].text, sourceRowData.line[RightSide].text); + QCOMPARE(resultRowData.line[RightSide].textLineType, sourceRowData.line[RightSide].textLineType); } } } @@ -1429,10 +1429,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch() const RowData &origRowData = origChunkData.rows.at(k); const RowData &resultRowData = resultChunkData.rows.at(k); QCOMPARE(resultRowData.equal, origRowData.equal); - QCOMPARE(resultRowData.leftLine.text, origRowData.leftLine.text); - QCOMPARE(resultRowData.leftLine.textLineType, origRowData.leftLine.textLineType); - QCOMPARE(resultRowData.rightLine.text, origRowData.rightLine.text); - QCOMPARE(resultRowData.rightLine.textLineType, origRowData.rightLine.textLineType); + QCOMPARE(resultRowData.line[LeftSide].text, origRowData.line[LeftSide].text); + QCOMPARE(resultRowData.line[LeftSide].textLineType, origRowData.line[LeftSide].textLineType); + QCOMPARE(resultRowData.line[RightSide].text, origRowData.line[RightSide].text); + QCOMPARE(resultRowData.line[RightSide].textLineType, origRowData.line[RightSide].textLineType); } } } @@ -1457,10 +1457,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch_data() auto appendRow = [](ChunkData *chunk, const QString &left, const QString &right) { RowData row; row.equal = (left == right); - row.leftLine.text = left; - row.leftLine.textLineType = left.isEmpty() ? TextLineData::Separator : TextLineData::TextLine; - row.rightLine.text = right; - row.rightLine.textLineType = right.isEmpty() ? TextLineData::Separator : TextLineData::TextLine; + row.line[LeftSide].text = left; + row.line[LeftSide].textLineType = left.isEmpty() ? TextLineData::Separator : TextLineData::TextLine; + row.line[RightSide].text = right; + row.line[RightSide].textLineType = right.isEmpty() ? TextLineData::Separator : TextLineData::TextLine; chunk->rows.append(row); }; ChunkData chunk; @@ -1664,8 +1664,8 @@ void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch() const ChunkData result = DiffEditorDocument::filterChunk(chunk, selection, revert); QCOMPARE(result.rows.size(), rows.size()); for (int i = 0; i < rows.size(); ++i) { - QCOMPARE(result.rows.at(i).leftLine.text, rows.at(i).first); - QCOMPARE(result.rows.at(i).rightLine.text, rows.at(i).second); + QCOMPARE(result.rows.at(i).line[LeftSide].text, rows.at(i).first); + QCOMPARE(result.rows.at(i).line[RightSide].text, rows.at(i).second); } } diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp index 1dbaf6c73c3..c3dde260f41 100644 --- a/src/plugins/diffeditor/diffutils.cpp +++ b/src/plugins/diffeditor/diffutils.cpp @@ -294,9 +294,9 @@ FileData DiffUtils::calculateContextData(const ChunkData &originalData, int cont break; RowData rowData = originalData.rows.at(i); chunkData.rows.append(rowData); - if (rowData.leftLine.textLineType == TextLineData::TextLine) + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) ++leftLineNumber; - if (rowData.rightLine.textLineType == TextLineData::TextLine) + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) ++rightLineNumber; ++i; } @@ -351,15 +351,15 @@ QString DiffUtils::makePatch(const ChunkData &chunkData, int i = 0; for (i = rowCount; i > 0; i--) { const RowData &rowData = chunkData.rows.at(i - 1); - if (rowData.leftLine.textLineType != TextLineData::Separator - || rowData.rightLine.textLineType != TextLineData::TextLine) + if (rowData.line[LeftSide].textLineType != TextLineData::Separator + || rowData.line[RightSide].textLineType != TextLineData::TextLine) break; } const int leftSeparator = i; for (i = rowCount; i > 0; i--) { const RowData &rowData = chunkData.rows.at(i - 1); - if (rowData.rightLine.textLineType != TextLineData::Separator - || rowData.leftLine.textLineType != TextLineData::TextLine) + if (rowData.line[RightSide].textLineType != TextLineData::Separator + || rowData.line[LeftSide].textLineType != TextLineData::TextLine) break; } const int rightSeparator = i; @@ -409,7 +409,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData, } if (i < chunkData.rows.size()) { const QString line = makePatchLine(' ', - rowData.rightLine.text, + rowData.line[RightSide].text, lastChunk, i == chunkData.rows.size() - 1); @@ -421,10 +421,10 @@ QString DiffUtils::makePatch(const ChunkData &chunkData, diffText += line; } } else { - if (rowData.leftLine.textLineType == TextLineData::TextLine) - leftBuffer.append(rowData.leftLine); - if (rowData.rightLine.textLineType == TextLineData::TextLine) - rightBuffer.append(rowData.rightLine); + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) + leftBuffer.append(rowData.line[LeftSide]); + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) + rightBuffer.append(rowData.line[RightSide]); } } diff --git a/src/plugins/diffeditor/diffutils.h b/src/plugins/diffeditor/diffutils.h index f321349ff31..6a8859376bc 100644 --- a/src/plugins/diffeditor/diffutils.h +++ b/src/plugins/diffeditor/diffutils.h @@ -64,11 +64,10 @@ class DIFFEDITOR_EXPORT RowData { public: RowData() = default; RowData(const TextLineData &l) - : leftLine(l), rightLine(l), equal(true) {} + : line({l, l}), equal(true) {} RowData(const TextLineData &l, const TextLineData &r) - : leftLine(l), rightLine(r) {} - TextLineData leftLine; - TextLineData rightLine; + : line({l, r}) {} + std::array line{}; bool equal = false; }; diff --git a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp index 1d093752176..4a9ecf66375 100644 --- a/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp +++ b/src/plugins/diffeditor/sidebysidediffeditorwidget.cpp @@ -933,8 +933,8 @@ void SideBySideDiffEditorWidget::showDiff() m_rightEditor->setChunkIndex(blockNumber, chunkData.rows.count(), j); for (const RowData &rowData : chunkData.rows) { - TextLineData leftLineData = rowData.leftLine; - TextLineData rightLineData = rowData.rightLine; + TextLineData leftLineData = rowData.line[LeftSide]; + TextLineData rightLineData = rowData.line[RightSide]; if (leftLineData.textLineType == TextLineData::TextLine) { leftText += leftLineData.text; lastLeftLineNumber = leftLineNumber; @@ -953,11 +953,11 @@ void SideBySideDiffEditorWidget::showDiff() } if (!rowData.equal) { - if (rowData.leftLine.textLineType == TextLineData::TextLine) + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) leftFormats[blockNumber].append(DiffSelection(&m_controller.m_leftLineFormat)); else leftFormats[blockNumber].append(DiffSelection(&m_spanLineFormat)); - if (rowData.rightLine.textLineType == TextLineData::TextLine) + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) rightFormats[blockNumber].append(DiffSelection(&m_controller.m_rightLineFormat)); else rightFormats[blockNumber].append(DiffSelection(&m_spanLineFormat)); @@ -1064,9 +1064,9 @@ void SideBySideDiffEditorWidget::slotLeftJumpToOriginalFileRequested( for (int j = 0; j < chunkData.rows.count(); j++) { const RowData rowData = chunkData.rows.at(j); - if (rowData.leftLine.textLineType == TextLineData::TextLine) + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) leftLineNumber++; - if (rowData.rightLine.textLineType == TextLineData::TextLine) + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) rightLineNumber++; if (leftLineNumber == lineNumber) { int colNr = rowData.equal ? columnNumber : 0; diff --git a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp index fcd52c6d910..33a5a766829 100644 --- a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp +++ b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp @@ -419,7 +419,7 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData } if (i < chunkData.rows.count()) { const QString line = DiffUtils::makePatchLine(' ', - rowData.rightLine.text, + rowData.line[RightSide].text, lastChunk, i == chunkData.rows.count() - 1); @@ -438,12 +438,12 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData charCount += line.count(); } } else { - if (rowData.leftLine.textLineType == TextLineData::TextLine) { - leftBuffer.append(rowData.leftLine); + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) { + leftBuffer.append(rowData.line[LeftSide]); leftRowsBuffer.append(i); } - if (rowData.rightLine.textLineType == TextLineData::TextLine) { - rightBuffer.append(rowData.rightLine); + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) { + rightBuffer.append(rowData.line[RightSide]); rightRowsBuffer.append(i); } } @@ -692,9 +692,9 @@ void UnifiedDiffEditorWidget::jumpToOriginalFile(const QTextCursor &cursor) int newRightLineNumber = chunkData.startingLineNumber[RightSide]; for (const RowData &rowData : chunkData.rows) { - if (rowData.leftLine.textLineType == TextLineData::TextLine) + if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) newLeftLineNumber++; - if (rowData.rightLine.textLineType == TextLineData::TextLine) + if (rowData.line[RightSide].textLineType == TextLineData::TextLine) newRightLineNumber++; if (newLeftLineNumber == leftLineNumber) { m_controller.jumpToOriginalFile(leftFileName, newRightLineNumber, 0);