Commit 4cc686cb authored by Michael Reeves's avatar Michael Reeves

Optimize SourceData::FileData::preprocess

Drop ts.readAll() elimates redundant read of file data.
parent ee888dc7
......@@ -585,6 +585,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
qint64 lastOffset = 0;
m_bIncompleteConversion = false;
m_unicodeBuf.clear();
while(!ts.atEnd())
{
......@@ -613,8 +614,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
}
++lineCount;
lastOffset = ts.pos();
//There is no peek in QTextStream so work around that limitation by reading next character here.
switch(curChar.unicode())
{
case '\n':
......@@ -623,6 +623,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
case '\r':
if(lastOffset < m_size)
{
//workaround for lack of peak API in QTextStream.
qint64 j;
for(j = 0; j < 4 && lastOffset + j < m_size; j++)
{
......@@ -646,6 +647,8 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
//kdiff3 internally uses only unix style endings for simplicity.
//line.append('\n');
m_v[lineCount - 1].setLine(line);
m_unicodeBuf.append(line).append('\n');
lastOffset = m_unicodeBuf->length();
}
m_v.push_back(LineData(lastOffset));
......@@ -655,10 +658,6 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
if(!vOrigDataLineEndStyle.isEmpty())
m_eLineEndStyle = vOrigDataLineEndStyle[0];
ts.seek(0);
m_unicodeBuf = ts.readAll();
ba.clear();
int ucSize = m_unicodeBuf.length();
const QChar* p = m_unicodeBuf.unicode();
......
......@@ -77,9 +77,10 @@ class LineData
{
private:
QString pLine;
quint32 pFirstNonWhiteChar = 0;
Q_DECL_DEPRECATED const QChar* pLine_old = nullptr;
Q_DECL_DEPRECATED const QChar* pFirstNonWhiteChar = nullptr;
Q_DECL_DEPRECATED const QChar* pFirstNonWhiteChar_old = nullptr;
int mSize = 0;
qint64 mOffset = 0;
......@@ -91,8 +92,8 @@ class LineData
Q_REQUIRED_RESULT inline int size() const { Q_ASSERT(pLine.length() == mSize); return pLine.length(); }
Q_DECL_DEPRECATED inline void setSize(const int newSize) { mSize = newSize; }
Q_DECL_DEPRECATED inline void setFirstNonWhiteChar(const QChar* firstNonWhiteChar) { pFirstNonWhiteChar = firstNonWhiteChar;}
inline const QChar* getFirstNonWhiteChar() const { return pFirstNonWhiteChar; }
Q_DECL_DEPRECATED inline void setFirstNonWhiteChar(const QChar* firstNonWhiteChar) { pFirstNonWhiteChar_old = firstNonWhiteChar;}
Q_DECL_DEPRECATED inline const QChar* getFirstNonWhiteChar() const { return pFirstNonWhiteChar_old; }
Q_REQUIRED_RESULT inline const QString getLine() const { return pLine; }
Q_DECL_DEPRECATED Q_REQUIRED_RESULT inline const QChar* getRawLine() const { return pLine_old; }
......@@ -102,7 +103,7 @@ class LineData
inline void setOffset(qint64 inOffset) { mOffset = inOffset; }
int width(int tabSize) const; // Calcs width considering tabs.
//int occurrences;
bool whiteLine() const { return pFirstNonWhiteChar - pLine_old == mSize; }
bool whiteLine() const { return pFirstNonWhiteChar_old - pLine_old == mSize; }
bool isPureComment() const { return bContainsPureComment; }
void setPureComment(const bool bPureComment) { bContainsPureComment = bPureComment; }
......
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