From f4d3ebc9bc6eede068c3e520be3bb34b81683051 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 14 May 2024 20:26:32 +0800 Subject: [PATCH] optimize: use constData() if possible --- RedPandaIDE/compiler/compiler.cpp | 4 ++-- RedPandaIDE/parser/cpppreprocessor.cpp | 2 +- RedPandaIDE/parser/cpptokenizer.cpp | 21 ++++++++++--------- RedPandaIDE/parser/cpptokenizer.h | 6 +++--- .../environmentappearancewidget.cpp | 3 ++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 2f7151fb..8e7b31e6 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -148,7 +148,7 @@ int Compiler::getLineNumberFromOutputLine(QString &line) pos = line.indexOf(','); } if (pos>=0) { - result = QStringView(line.data(), pos).toInt(); + result = QStringView(line.constData(), pos).toInt(); if (result > 0) line.remove(0,pos+1); } else { @@ -168,7 +168,7 @@ int Compiler::getColunmnFromOutputLine(QString &line) pos = line.indexOf(','); } if (pos>=0) { - result = QStringView(line.data(), pos).toInt(); + result = QStringView(line.constData(), pos).toInt(); if (result > 0) line.remove(0,pos+1); } diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 97c2c8e4..55c67b3b 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -1037,7 +1037,7 @@ QStringList CppPreprocessor::removeComments(const QStringList &text) currentType=ContentType::Other; break; case ContentType::RawString: - if (QStringView(line.data(), pos).endsWith(')'+delimiter)) + if (QStringView(line.constData(), pos).endsWith(')'+delimiter)) currentType = ContentType::Other; break; case ContentType::Other: diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index f317ef7c..65c01e71 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -49,7 +49,8 @@ void CppTokenizer::tokenize(const QStringList &buffer) mBufferStr+='\n'; mBufferStr+=mBuffer[i]; } - mStart = mBufferStr.data(); + mBufferStr.append(QChar(0)); + mStart = mBufferStr.constData(); mCurrent = mStart; mLineCount = mStart; QString s = ""; @@ -271,7 +272,7 @@ QString CppTokenizer::getNextToken(TokenType *pTokenType) if (*(mCurrent+1)!='[') { *pTokenType=TokenType::LambdaCaptures; countLines(); - QChar* backup=mCurrent; + const QChar* backup=mCurrent; skipPair('[',']'); result = QString(backup,mCurrent-backup); done = true; @@ -399,7 +400,7 @@ QString CppTokenizer::getNextToken(TokenType *pTokenType) QString CppTokenizer::getNumber() { - QChar* offset = mCurrent; + const QChar* offset = mCurrent; if (isDigitChar(*mCurrent)) { while (isDigitChar(*mCurrent) || isHexChar(*mCurrent)) { @@ -424,7 +425,7 @@ QString CppTokenizer::getNumber() QString CppTokenizer::getPreprocessor() { - QChar *offset = mCurrent; + const QChar *offset = mCurrent; skipToEOL(); return QString(offset, mCurrent-offset); } @@ -436,7 +437,7 @@ QString CppTokenizer::getWord() skipToNextToken(); // Get next word... - QChar* offset = mCurrent; + const QChar* offset = mCurrent; mCurrent++; // Copy the word ahead of us @@ -474,7 +475,7 @@ QString CppTokenizer::getWord() if (currentWord!="operator") { // Skip template contents, but keep template variable types if (*mCurrent == '<') { - offset = mCurrent; + const QChar* offset = mCurrent; if (bFoundTemplate) { skipTemplateArgs(); @@ -486,7 +487,7 @@ QString CppTokenizer::getWord() if (*(mCurrent+1)!='[') { // Append array stuff while(true) { - offset = mCurrent; + const QChar* offset = mCurrent; skipPair('[', ']'); result += QString(offset,mCurrent-offset); simplifyArgs(result); @@ -647,7 +648,7 @@ void CppTokenizer::skipPair(const QChar &cStart, const QChar cEnd) bool CppTokenizer::skipAngleBracketPair() { - QChar* backup=mCurrent; + const QChar* backup=mCurrent; QVector stack; while (*mCurrent != '\0') { switch((*mCurrent).unicode()) { @@ -732,7 +733,7 @@ void CppTokenizer::skipRawString() case ')': if (noEscape) { bool ok=true; - QChar* pChar=mCurrent+1; + const QChar* pChar=mCurrent+1; for (int i=0;iunicode()) { diff --git a/RedPandaIDE/parser/cpptokenizer.h b/RedPandaIDE/parser/cpptokenizer.h index ced976a9..dd1782c6 100644 --- a/RedPandaIDE/parser/cpptokenizer.h +++ b/RedPandaIDE/parser/cpptokenizer.h @@ -146,9 +146,9 @@ private: private: QStringList mBuffer; QString mBufferStr; - QChar* mStart; - QChar* mCurrent; - QChar* mLineCount; + const QChar* mStart; + const QChar* mCurrent; + const QChar* mLineCount; int mCurrentLine; QString mLastToken; TokenList mTokenList; diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp index 4a61dd28..4c40593d 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp @@ -88,8 +88,9 @@ void EnvironmentAppearanceWidget::doSave() pMainWindow->applySettings(); } -void EnvironmentAppearanceWidget::updateIcons(const QSize &size) +void EnvironmentAppearanceWidget::updateIcons(const QSize & size) { + Q_UNUSED(size); pIconsManager->setIcon(ui->btnCustomize, IconsManager::ACTION_EDIT_COPY); pIconsManager->setIcon(ui->btnOpenCustomThemeFolder, IconsManager::ACTION_MISC_FOLDER); pIconsManager->setIcon(ui->btnRemoveCustomTheme, IconsManager::ACTION_MISC_REMOVE);