Commit 5bb740c0 authored by Michael Reeves's avatar Michael Reeves

Track lines as QString not QChar*

parent 831eac0b
......@@ -41,7 +41,7 @@ QString MergeEditLine::getString(const QVector<LineData>* pLineDataA, const QVec
return QString();
}
return QString(pld->getLine(), pld->size());
return pld->getLine();
}
else
{
......
......@@ -592,8 +592,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
if(lineCount >= TYPE_MAX(LineCount) - 5)
return false;
m_v.push_back(LineData());
m_v[lineCount].setOffset(lastOffset);
m_v.push_back(LineData(lastOffset));
ts >> curChar;
//QTextStream::readLine doesn't tell us abount line endings.
......@@ -644,8 +643,9 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
vOrigDataLineEndStyle.push_back(eLineEndStyleUndefined);
break;
}
//kdiff3 internally uses only unix style endings and assumes for simplicity.
//kdiff3 internally uses only unix style endings for simplicity.
line.append('\n');
m_v[lineCount].setLine(line);
}
m_bIsText = true;
......@@ -673,7 +673,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
{
--lineLength;
}
m_v[lineIdx].setFirstNonWhiteChar(m_v[lineIdx].getLine() + std::min(whiteLength, lineLength));
m_v[lineIdx].setFirstNonWhiteChar(m_v[lineIdx].getRawLine() + std::min(whiteLength, lineLength));
if(lineIdx < vOrigDataLineEndStyle.count() && bPreserveCR && i < ucSize)
{
++lineLength;
......
......@@ -58,10 +58,10 @@ bool LineData::equal(const LineData& l1, const LineData& l2, bool bStrict)
return false;
// Ignore white space diff
const QChar* p1 = l1.getLine();
const QChar* p1 = l1.getRawLine();
const QChar* p1End = p1 + l1.size();
const QChar* p2 = l2.getLine();
const QChar* p2 = l2.getRawLine();
const QChar* p2End = p2 + l2.size();
if(g_bIgnoreWhiteSpace)
......@@ -563,10 +563,10 @@ static bool runDiff(const QVector<LineData>* p1, const qint32 index1, LineRef si
GnuDiff::comparison comparisonInput;
memset(&comparisonInput, 0, sizeof(comparisonInput));
comparisonInput.parent = nullptr;
comparisonInput.file[0].buffer = (*p1)[index1].getLine(); //ptr to buffer
comparisonInput.file[0].buffered = ((*p1)[size1 - 1].getLine() - (*p1)[index1].getLine() + (*p1)[size1 - 1].size()); // size of buffer
comparisonInput.file[1].buffer = (*p2)[index2].getLine(); //ptr to buffer
comparisonInput.file[1].buffered = ((*p2)[size2 - 1].getLine() - (*p2)[index2].getLine() + (*p2)[size2 - 1].size()); // size of buffer
comparisonInput.file[0].buffer = (*p1)[index1].getRawLine(); //ptr to buffer
comparisonInput.file[0].buffered = ((*p1)[size1 - 1].getRawLine() - (*p1)[index1].getRawLine() + (*p1)[size1 - 1].size()); // size of buffer
comparisonInput.file[1].buffer = (*p2)[index2].getRawLine(); //ptr to buffer
comparisonInput.file[1].buffered = ((*p2)[size2 - 1].getRawLine() - (*p2)[index2].getRawLine() + (*p2)[size2 - 1].size()); // size of buffer
gnuDiff.ignore_white_space = GnuDiff::IGNORE_ALL_SPACE; // I think nobody needs anything else ...
gnuDiff.bIgnoreWhiteSpace = true;
......@@ -1344,11 +1344,11 @@ bool Diff3Line::fineDiff(bool inBTextsTotalEqual, const e_SrcSelector selector,
if((!k1.isValid() && k2.isValid()) || (k1.isValid() && !k2.isValid())) bTextsTotalEqual = false;
if(k1.isValid() && k2.isValid())
{
if((*v1)[k1].size() != (*v2)[k2].size() || memcmp((*v1)[k1].getLine(), (*v2)[k2].getLine(), (*v1)[k1].size() << 1) != 0)
if((*v1)[k1].size() != (*v2)[k2].size() || memcmp((*v1)[k1].getRawLine(), (*v2)[k2].getRawLine(), (*v1)[k1].size() << 1) != 0)
{
bTextsTotalEqual = false;
DiffList* pDiffList = new DiffList;
calcDiff((*v1)[k1].getLine(), (*v1)[k1].size(), (*v2)[k2].getLine(), (*v2)[k2].size(), *pDiffList, 2, maxSearchLength);
calcDiff((*v1)[k1].getRawLine(), (*v1)[k1].size(), (*v2)[k2].getRawLine(), (*v2)[k2].size(), *pDiffList, 2, maxSearchLength);
// Optimize the diff list.
DiffList::iterator dli;
......
......@@ -76,7 +76,9 @@ typedef std::list<Diff> DiffList;
class LineData
{
private:
const QChar* pLine = nullptr;
QString pLine;
const QChar* pLine_old = nullptr;
const QChar* pFirstNonWhiteChar = nullptr;
int mSize = 0;
......@@ -84,20 +86,23 @@ class LineData
bool bContainsPureComment = false;
public:
LineData() = default;
inline LineData(const qint64 inOffset) { mOffset = inOffset; }
inline int size() const { return mSize; }
inline void setSize(const int newSize) { mSize = newSize; }
inline void setFirstNonWhiteChar(const QChar* firstNonWhiteChar) { pFirstNonWhiteChar = firstNonWhiteChar;}
inline const QChar* getFirstNonWhiteChar() const { return pFirstNonWhiteChar; }
inline const QChar* getLine() const { return pLine; }
inline void setLine(const QChar* line) { pLine = line;}
inline const QString getLine() const { return pLine; }
inline const QChar* getRawLine() const { return pLine_old; }
inline void setLine(const QChar* line) { pLine_old = line;}
inline void setLine(const QString& line) { pLine = line;}
inline qint64 getOffset() { return mOffset; }
inline void setOffset(qint64 inOffset) { mOffset = inOffset; }
int width(int tabSize) const; // Calcs width considering tabs.
//int occurrences;
bool whiteLine() const { return pFirstNonWhiteChar - pLine == mSize; }
bool whiteLine() const { return pFirstNonWhiteChar - pLine_old == mSize; }
bool isPureComment() const { return bContainsPureComment; }
void setPureComment(const bool bPureComment) { bContainsPureComment = bPureComment; }
......@@ -187,7 +192,7 @@ class Diff3Line
{
const LineData* pld = getLineData(src);
if(pld)
return QString(pld->getLine(), pld->size());
return pld->getLine();
else
return QString();
}
......
......@@ -865,7 +865,7 @@ void DiffTextWindowData::writeLine(
{
// First calculate the "changed" information for each character.
int i = 0;
QString lineString(pld->getLine(), pld->size());
QString lineString = pld->getLine();
if(!lineString.isEmpty())
{
switch(lineString[lineString.length() - 1].unicode())
......@@ -1149,7 +1149,7 @@ QString DiffTextWindowData::getString(int d3lIdx)
else
{
const LineData* ld = &(*m_pLineData)[lineIdx];
return QString(ld->getLine(), ld->size());
return ld->getLine();
}
return QString();
}
......@@ -1240,9 +1240,8 @@ QString DiffTextWindow::getSelection()
if(lineIdx != -1)
{
const QChar* pLine = (*d->m_pLineData)[lineIdx].getLine();
int size = (*d->m_pLineData)[lineIdx].size();
QString lineString = QString(pLine, size);
QString lineString = (*d->m_pLineData)[lineIdx].getLine();
if(d->m_bWordWrap)
{
......
......@@ -1253,8 +1253,8 @@ void MergeResultWindow::collectHistoryInformation(
QString historyLead;
{
const LineData* pld = id3l->getLineData(src);
QString s(pld->getLine(), pld->size());
historyLead = calcHistoryLead(s);
historyLead = calcHistoryLead(pld->getLine());
}
QRegExp historyStart(m_pOptions->m_historyStartRegExp);
if(id3l == iHistoryEnd)
......@@ -1271,9 +1271,10 @@ void MergeResultWindow::collectHistoryInformation(
{
const LineData* pld = id3l->getLineData(src);
if(!pld) continue;
QString s(pld->getLine(), pld->size());
if(historyLead.isEmpty()) historyLead = calcHistoryLead(s);
QString sLine = s.mid(historyLead.length());
const QString& oriLine = pld->getLine();
if(historyLead.isEmpty()) historyLead = calcHistoryLead(oriLine);
QString sLine = oriLine.mid(historyLead.length());
if((!bUseRegExp && !sLine.trimmed().isEmpty() && bPrevLineIsEmpty) || (bUseRegExp && newHistoryEntry.exactMatch(sLine)))
{
if(!key.isEmpty() && !melList.empty())
......@@ -1298,7 +1299,7 @@ void MergeResultWindow::collectHistoryInformation(
melList.clear();
melList.push_back(MergeEditLine(id3l, src));
}
else if(!historyStart.exactMatch(s))
else if(!historyStart.exactMatch(oriLine))
{
melList.push_back(MergeEditLine(id3l, src));
}
......
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