- optimization: use QString::constData() instead of QString::data() if possible

- fix: Can't correctly parse template parameters that contains "->", like "std::queue<std::function<auto()->void>>";
This commit is contained in:
Roy Qu 2024-05-14 21:19:42 +08:00
parent f4d3ebc9bc
commit 454dcbadcb
15 changed files with 32 additions and 14 deletions

View File

@ -1,6 +1,7 @@
Red Panda C++ Version 3.1 Red Panda C++ Version 3.1
- fix: Can't correctly select in column mode. - fix: Can't correctly select in column mode.
- fix: Can't correctly parse template parameters that contains "->", like "std::queue<std::function<auto()->void>>";
Red Panda C++ Version 3.0 Red Panda C++ Version 3.0
@ -174,6 +175,7 @@ Red Panda C++ Version 3.0
- enhancement: Show full filepath in the tooltip of editor tab. - enhancement: Show full filepath in the tooltip of editor tab.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.
- change: Use ctrl+mouseMove event to highlight jumpable symbols (instead of ctrl+tooltip). - change: Use ctrl+mouseMove event to highlight jumpable symbols (instead of ctrl+tooltip).
- enhancement: Auto adjust position of the suggestion popup window. - enhancement: Auto adjust position of the suggestion popup window.

View File

@ -49,7 +49,8 @@ void CppTokenizer::tokenize(const QStringList &buffer)
mBufferStr+='\n'; mBufferStr+='\n';
mBufferStr+=mBuffer[i]; mBufferStr+=mBuffer[i];
} }
mBufferStr.append(QChar(0)); //QByteArray is always '\0'-terminated unless it's created by QbyteArray::fromRawData()
//mBufferStr.append(QChar(0));
mStart = mBufferStr.constData(); mStart = mBufferStr.constData();
mCurrent = mStart; mCurrent = mStart;
mLineCount = mStart; mLineCount = mStart;
@ -695,8 +696,8 @@ bool CppTokenizer::skipAngleBracketPair()
return false; return false;
case '-': case '-':
if (*(mCurrent+1)=='>') { if (*(mCurrent+1)=='>') {
mCurrent=backup; mCurrent+=2;
return false; continue;
} }
break; break;
case '.': case '.':

View File

@ -89,7 +89,7 @@ bool ProblemCaseValidator::equalIgnoringSpaces(const QString &s1, const QString
QStringList ProblemCaseValidator::split(const QString &s) QStringList ProblemCaseValidator::split(const QString &s)
{ {
QStringList result; QStringList result;
const QChar* p = s.data(); const QChar* p = getNullTerminatedStringData(s);
const QChar* start = p; const QChar* start = p;
while (p->unicode()!=0) { while (p->unicode()!=0) {
if (p->isSpace()) { if (p->isSpace()) {

View File

@ -252,7 +252,7 @@ QString QConsole::selText()
QString s = mContents.getLine(Last); QString s = mContents.getLine(Last);
if (Last == mContents.lines()) if (Last == mContents.lines())
s+= this->mCommand; s+= this->mCommand;
result.append(s.data(), ColTo); result.append(s.constData(), ColTo);
return result; return result;
} }
} }

View File

@ -4498,7 +4498,7 @@ QString QSynEdit::selText() const
result+=lineBreak(); result+=lineBreak();
} }
const QString &line = mDocument->getLine(lastLine); const QString &line = mDocument->getLine(lastLine);
result.append(line.data(), charTo-1); result.append(line.constData(), charTo-1);
return result; return result;
} }
} }

View File

@ -16,6 +16,7 @@
*/ */
#include "asm.h" #include "asm.h"
#include "../constants.h" #include "../constants.h"
#include <qt_utils/utils.h>
#include <QDebug> #include <QDebug>
namespace QSynedit { namespace QSynedit {
@ -1706,7 +1707,7 @@ void ASMSyntaxer::next()
void ASMSyntaxer::setLine(const QString &newLine, int lineNumber) void ASMSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = getNullTerminatedStringData(mLineString);
mLineNumber = lineNumber; mLineNumber = lineNumber;
mRun = 0; mRun = 0;
next(); next();

View File

@ -60,7 +60,7 @@ public:
static const QSet<QString> Directives; static const QSet<QString> Directives;
static const QSet<QString> ATTDirectives; static const QSet<QString> ATTDirectives;
private: private:
QChar* mLine; const QChar* mLine;
QString mLineString; QString mLineString;
int mLineNumber; int mLineNumber;
int mRun; int mRun;

View File

@ -16,6 +16,7 @@
*/ */
#include "glsl.h" #include "glsl.h"
#include "../constants.h" #include "../constants.h"
#include <qt_utils/utils.h>
#include <QFont> #include <QFont>
@ -1360,7 +1361,7 @@ void GLSLSyntaxer::next()
void GLSLSyntaxer::setLine(const QString &newLine, int lineNumber) void GLSLSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = getNullTerminatedStringData(mLineString);
mLineNumber = lineNumber; mLineNumber = lineNumber;
mRun = 0; mRun = 0;
mRange.blockStarted = 0; mRange.blockStarted = 0;

View File

@ -134,7 +134,7 @@ private:
SyntaxState mRange; SyntaxState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
QString mLineString; QString mLineString;
QChar* mLine; const QChar* mLine;
int mLineSize; int mLineSize;
int mRun; int mRun;
int mStringLen; int mStringLen;

View File

@ -16,6 +16,7 @@
*/ */
#include "makefile.h" #include "makefile.h"
#include "../constants.h" #include "../constants.h"
#include <qt_utils/utils.h>
//#include <QDebug> //#include <QDebug>
namespace QSynedit { namespace QSynedit {
@ -643,7 +644,7 @@ void MakefileSyntaxer::next()
void MakefileSyntaxer::setLine(const QString &newLine, int lineNumber) void MakefileSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = getNullTerminatedStringData(mLineString);
mLineNumber = lineNumber; mLineNumber = lineNumber;
mRun = 0; mRun = 0;
next(); next();

View File

@ -72,7 +72,7 @@ public:
static const QSet<QString> Directives; static const QSet<QString> Directives;
private: private:
QChar* mLine; const QChar* mLine;
QString mLineString; QString mLineString;
int mLineNumber; int mLineNumber;
int mRun; int mRun;

View File

@ -16,6 +16,7 @@
*/ */
#include "textfile.h" #include "textfile.h"
#include "../constants.h" #include "../constants.h"
#include <qt_utils/utils.h>
//#include <QDebug> //#include <QDebug>
namespace QSynedit { namespace QSynedit {
@ -102,7 +103,7 @@ void TextSyntaxer::next()
void TextSyntaxer::setLine(const QString &newLine, int lineNumber) void TextSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = getNullTerminatedStringData(mLineString);
mLineNumber = lineNumber; mLineNumber = lineNumber;
mRun = 0; mRun = 0;
next(); next();

View File

@ -42,7 +42,7 @@ public:
static const QSet<QString> Directives; static const QSet<QString> Directives;
private: private:
QChar* mLine; const QChar* mLine;
QString mLineString; QString mLineString;
int mLineNumber; int mLineNumber;
int mRun; int mRun;

View File

@ -756,3 +756,12 @@ QString replacePrefix(const QString &oldString, const QString &prefix, const QSt
} }
return result; return result;
} }
const QChar *getNullTerminatedStringData(const QString &str)
{
const QChar* result = str.constData();
if (result[str.size()]!=QChar(0)) {
result = str.data();
}
return result;
}

View File

@ -69,6 +69,8 @@ public:
/* text processing utils */ /* text processing utils */
const QByteArray guessTextEncoding(const QByteArray& text); const QByteArray guessTextEncoding(const QByteArray& text);
const QChar *getNullTerminatedStringData(const QString& str);
bool isBinaryContent(const QByteArray& text); bool isBinaryContent(const QByteArray& text);
bool isTextAllAscii(const QByteArray& text); bool isTextAllAscii(const QByteArray& text);
bool isTextAllAscii(const QString& text); bool isTextAllAscii(const QString& text);