Commit 29042af9 authored by Michael Reeves's avatar Michael Reeves

Stop abusing []

Pass QVector<LineData> if that's needed don't make assumtions
about the memmory layout of classes especial ones we don't control.
parent 86b756db
......@@ -11,7 +11,7 @@
#include "MergeEditLine.h"
QString MergeEditLine::getString(const LineData* pLineDataA, const LineData* pLineDataB, const LineData* pLineDataC)
QString MergeEditLine::getString(const QVector<LineData>* pLineDataA, const QVector<LineData>* pLineDataB, const QVector<LineData>* pLineDataC)
{
if(isRemoved())
{
......@@ -29,11 +29,11 @@ QString MergeEditLine::getString(const LineData* pLineDataA, const LineData* pLi
const LineData* pld = nullptr;
Q_ASSERT(src == A || src == B || src == C);
if(src == A && d3l.getLineA().isValid())
pld = &pLineDataA[d3l.getLineA()];
pld = &(*pLineDataA)[d3l.getLineA()];
else if(src == B && d3l.getLineB().isValid())
pld = &pLineDataB[d3l.getLineB()];
pld = &(*pLineDataB)[d3l.getLineB()];
else if(src == C && d3l.getLineC().isValid())
pld = &pLineDataC[d3l.getLineC()];
pld = &(*pLineDataC)[d3l.getLineC()];
//Not an error.
if(pld == nullptr)
......
......@@ -47,7 +47,7 @@ class MergeEditLine
m_bLineRemoved = false;
m_src = None;
}
QString getString(const LineData* pLineDataA, const LineData* pLineDataB, const LineData* pLineDataC);
QString getString(const QVector<LineData>* pLineDataA, const QVector<LineData>* pLineDataB, const QVector<LineData>* pLineDataC);
bool isModified() { return !m_str.isEmpty() || (m_bLineRemoved && m_src == None); }
void setSource(e_SrcSelector src, bool bLineRemoved)
......
......@@ -159,17 +159,17 @@ QStringList SourceData::setData(const QString& data)
return errors;
}
const LineData* SourceData::getLineDataForDiff() const
const QVector<LineData>* SourceData::getLineDataForDiff() const
{
if(m_lmppData.m_pBuf == nullptr)
return m_normalData.m_v.size() > 0 ? &m_normalData.m_v[0] : nullptr;
return m_normalData.m_v.size() > 0 ? &m_normalData.m_v : nullptr;
else
return m_lmppData.m_v.size() > 0 ? &m_lmppData.m_v[0] : nullptr;
return m_lmppData.m_v.size() > 0 ? &m_lmppData.m_v : nullptr;
}
const LineData* SourceData::getLineDataForDisplay() const
const QVector<LineData>* SourceData::getLineDataForDisplay() const
{
return m_normalData.m_v.size() > 0 ? &m_normalData.m_v[0] : nullptr;
return m_normalData.m_v.size() > 0 ? &m_normalData.m_v : nullptr;
}
LineRef SourceData::getSizeLines() const
......
......@@ -33,8 +33,8 @@ class SourceData
qint64 getSizeBytes() const;
const char* getBuf() const;
const QString& getText() const;
const LineData* getLineDataForDisplay() const;
const LineData* getLineDataForDiff() const;
const QVector<LineData>* getLineDataForDisplay() const;
const QVector<LineData>* getLineDataForDiff() const;
void setFilename(const QString& filename);
void setFileAccess(const FileAccess& fileAccess);
......
This diff is collapsed.
......@@ -106,16 +106,16 @@ class Diff3LineVector;
class DiffBufferInfo
{
public:
const LineData* m_pLineDataA;
const LineData* m_pLineDataB;
const LineData* m_pLineDataC;
const QVector<LineData>* m_pLineDataA;
const QVector<LineData>* m_pLineDataB;
const QVector<LineData>* m_pLineDataC;
LineCount m_sizeA;
LineCount m_sizeB;
LineCount m_sizeC;
const Diff3LineList* m_pDiff3LineList;
const Diff3LineVector* m_pDiff3LineVector;
void init(Diff3LineList* d3ll, const Diff3LineVector* d3lv,
const LineData* pldA, LineCount sizeA, const LineData* pldB, LineCount sizeB, const LineData* pldC, LineCount sizeC);
const QVector<LineData>* pldA, LineCount sizeA, const QVector<LineData>* pldB, LineCount sizeB, const QVector<LineData>* pldC, LineCount sizeC);
};
class Diff3Line
......@@ -173,9 +173,9 @@ class Diff3Line
const LineData* getLineData(e_SrcSelector src) const
{
Q_ASSERT(m_pDiffBufferInfo != nullptr);
if(src == A && lineA >= 0) return &m_pDiffBufferInfo->m_pLineDataA[lineA];
if(src == B && lineB >= 0) return &m_pDiffBufferInfo->m_pLineDataB[lineB];
if(src == C && lineC >= 0) return &m_pDiffBufferInfo->m_pLineDataC[lineC];
if(src == A && lineA >= 0) return &(*m_pDiffBufferInfo->m_pLineDataA)[lineA];
if(src == B && lineB >= 0) return &(*m_pDiffBufferInfo->m_pLineDataB)[lineB];
if(src == C && lineC >= 0) return &(*m_pDiffBufferInfo->m_pLineDataC)[lineC];
return nullptr;
}
QString getString(const e_SrcSelector src) const
......@@ -194,7 +194,7 @@ class Diff3Line
return -1;
}
bool fineDiff(bool bTextsTotalEqual, const e_SrcSelector selector, const LineData* v1, const LineData* v2);
bool fineDiff(bool bTextsTotalEqual, const e_SrcSelector selector, const QVector<LineData>* v1, const QVector<LineData>* v2);
void mergeOneLine(e_MergeDetails& mergeDetails, bool& bConflict, bool& bLineRemoved, e_SrcSelector& src, bool bTwoInputs) const;
void getLineInfo(const e_SrcSelector winIdx, const bool isTriple, int& lineIdx,
......@@ -229,9 +229,9 @@ class Diff3Line
class Diff3LineList : public std::list<Diff3Line>
{
public:
bool fineDiff(const e_SrcSelector selector, const LineData* v1, const LineData* v2);
bool fineDiff(const e_SrcSelector selector, const QVector<LineData>* v1, const QVector<LineData>* v2);
void calcDiff3LineVector(Diff3LineVector& d3lv);
void calcWhiteDiff3Lines(const LineData* pldA, const LineData* pldB, const LineData* pldC);
void calcWhiteDiff3Lines(const QVector<LineData>* pldA, const QVector<LineData>* pldB, const QVector<LineData>* pldC);
//TODO: Add safety guards to prevent list from getting too large. Same problem as with QLinkedList.
int size() const {
if(std::list<Diff3Line>::size() > std::numeric_limits<int>::max())
......@@ -364,7 +364,7 @@ class ManualDiffHelpList: public std::list<ManualDiffHelpEntry>
bool isValidMove(int line1, int line2, e_SrcSelector winIdx1, e_SrcSelector winIdx2) const;
void insertEntry(e_SrcSelector winIdx, LineRef firstLine, LineRef lastLine);
bool runDiff(const LineData* p1, LineRef size1, const LineData* p2, LineRef size2, DiffList& diffList,
bool runDiff(const QVector<LineData>* p1, LineRef size1, const QVector<LineData>* p2, LineRef size2, DiffList& diffList,
e_SrcSelector winIdx1, e_SrcSelector winIdx2,
Options* pOptions);
};
......@@ -383,15 +383,15 @@ void calcDiff3LineListUsingBC(
void correctManualDiffAlignment(Diff3LineList& d3ll, ManualDiffHelpList* pManualDiffHelpList);
void calcDiff3LineListTrim(Diff3LineList& d3ll, const LineData* pldA, const LineData* pldB, const LineData* pldC, ManualDiffHelpList* pManualDiffHelpList);
void calcDiff3LineListTrim(Diff3LineList& d3ll, const QVector<LineData>* pldA, const QVector<LineData>* pldB, const QVector<LineData>* pldC, ManualDiffHelpList* pManualDiffHelpList);
bool fineDiff(
Diff3LineList& diff3LineList,
int selector,
const LineData* v1,
const LineData* v2);
const QVector<LineData>* v1,
const QVector<LineData>* v2);
inline bool isWhite(QChar c)
{
......
......@@ -84,7 +84,7 @@ class DiffTextWindowData
QTextCodec* m_pTextCodec;
e_LineEndStyle m_eLineEndStyle;
const LineData* m_pLineData;
const QVector<LineData>* m_pLineData;
int m_size;
QString m_filename;
bool m_bWordWrap;
......@@ -197,7 +197,7 @@ void DiffTextWindow::init(
const QString& filename,
QTextCodec* pTextCodec,
e_LineEndStyle eLineEndStyle,
const LineData* pLineData,
const QVector<LineData>* pLineData,
int size,
const Diff3LineVector* pDiff3LineVector,
const ManualDiffHelpList* pManualDiffHelpList,
......@@ -1115,7 +1115,7 @@ void DiffTextWindowData::draw(RLPainter& p, const QRect& invalidRect, int device
writeLine(
p, // QPainter
srcLineIdx == -1 ? nullptr : &m_pLineData[srcLineIdx], // Text in this line
srcLineIdx == -1 ? nullptr : &(*m_pLineData)[srcLineIdx], // Text in this line
pFineDiff1,
pFineDiff2,
line, // Line on the screen
......@@ -1148,7 +1148,7 @@ QString DiffTextWindowData::getString(int d3lIdx)
return QString();
else
{
const LineData* ld = &m_pLineData[lineIdx];
const LineData* ld = &(*m_pLineData)[lineIdx];
return QString(ld->getLine(), ld->size());
}
return QString();
......@@ -1240,8 +1240,8 @@ QString DiffTextWindow::getSelection()
if(lineIdx != -1)
{
const QChar* pLine = d->m_pLineData[lineIdx].getLine();
int size = d->m_pLineData[lineIdx].size();
const QChar* pLine = (*d->m_pLineData)[lineIdx].getLine();
int size = (*d->m_pLineData)[lineIdx].size();
QString lineString = QString(pLine, size);
if(d->m_bWordWrap)
......@@ -1354,7 +1354,7 @@ void DiffTextWindow::setSelection(LineRef firstLine, int startPos, LineRef lastL
if(d->m_winIdx == B) line = d3l->getLineB();
if(d->m_winIdx == C) line = d3l->getLineC();
if(line.isValid())
endPos = d->m_pLineData[line].width(d->m_pOptions->m_tabSize);
endPos = (*d->m_pLineData)[line].width(d->m_pOptions->m_tabSize);
}
if(d->m_bWordWrap && d->m_pDiff3LineVector != nullptr)
......
......@@ -35,7 +35,7 @@ public:
const QString& fileName,
QTextCodec* pTextCodec,
e_LineEndStyle eLineEndStyle,
const LineData* pLineData,
const QVector<LineData>* pLineData,
int size,
const Diff3LineVector* pDiff3LineVector,
const ManualDiffHelpList* pManualDiffHelpList,
......
......@@ -107,9 +107,9 @@ MergeResultWindow::MergeResultWindow(
}
void MergeResultWindow::init(
const LineData* pLineDataA, LineRef sizeA,
const LineData* pLineDataB, LineRef sizeB,
const LineData* pLineDataC, LineRef sizeC,
const QVector<LineData>* pLineDataA, LineRef sizeA,
const QVector<LineData>* pLineDataB, LineRef sizeB,
const QVector<LineData>* pLineDataC, LineRef sizeC,
const Diff3LineList* pDiff3LineList,
TotalDiffStatus* pTotalDiffStatus)
{
......
......@@ -35,9 +35,9 @@ public:
MergeResultWindow(QWidget* pParent, Options* pOptions, QStatusBar* pStatusBar);
void init(
const LineData* pLineDataA, LineRef sizeA,
const LineData* pLineDataB, LineRef sizeB,
const LineData* pLineDataC, LineRef sizeC,
const QVector<LineData>* pLineDataA, LineRef sizeA,
const QVector<LineData>* pLineDataB, LineRef sizeB,
const QVector<LineData>* pLineDataC, LineRef sizeC,
const Diff3LineList* pDiff3LineList,
TotalDiffStatus* pTotalDiffStatus
);
......@@ -132,9 +132,9 @@ private:
Options* m_pOptions = nullptr;
const LineData* m_pldA;
const LineData* m_pldB;
const LineData* m_pldC;
const QVector<LineData>* m_pldA;
const QVector<LineData>* m_pldB;
const QVector<LineData>* m_pldC;
LineRef m_sizeA;
LineRef m_sizeB;
LineRef m_sizeC;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment