optimize QHash/QMap iterations

This commit is contained in:
Roy Qu 2024-04-09 20:18:10 +08:00
parent 262ca6536c
commit 1f1d79c094
4 changed files with 14 additions and 12 deletions

View File

@ -2273,8 +2273,9 @@ void RegisterModel::updateNames(const QStringList &regNames)
void RegisterModel::updateValues(const QHash<int, QString> registerValues) void RegisterModel::updateValues(const QHash<int, QString> registerValues)
{ {
foreach(int row, registerValues.keys()){ for(auto it = registerValues.begin();it!=registerValues.end();++it) {
mRegisterValues[row] = registerValues[row]; int row = it.key();
mRegisterValues[row] = it.value();
} }
emit dataChanged(createIndex(0,1), emit dataChanged(createIndex(0,1),
createIndex(mRegisterNames.count()-1,1)); createIndex(mRegisterNames.count()-1,1));

View File

@ -3508,8 +3508,8 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
} else { } else {
switch(calcParserLanguage()) { switch(calcParserLanguage()) {
case ParserLanguage::CPlusPlus: case ParserLanguage::CPlusPlus:
foreach (const QString& keyword, CppKeywords.keys()) { for(auto it = CppKeywords.begin();it!=CppKeywords.end();++it) {
keywords.insert(keyword); keywords.insert(it.key());
} }
break; break;
case ParserLanguage::C: case ParserLanguage::C:
@ -3518,8 +3518,8 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
#ifdef ENABLE_SDCC #ifdef ENABLE_SDCC
case ParserLanguage::SDCC: case ParserLanguage::SDCC:
keywords = CKeywords; keywords = CKeywords;
foreach (const QString& keyword, SDCCKeywords.keys()) { for(auto it = SDCCKeywords.begin();it!=SDCCKeywords.end();++it) {
keywords.insert(keyword); keywords.insert(it.key());
} }
break; break;
#endif #endif
@ -5398,8 +5398,8 @@ void Editor::applySettings()
#ifdef ENABLE_SDCC #ifdef ENABLE_SDCC
if (!inProject() && pSettings->compilerSets().defaultSet() if (!inProject() && pSettings->compilerSets().defaultSet()
&& pSettings->compilerSets().defaultSet()->compilerType()==CompilerType::SDCC) { && pSettings->compilerSets().defaultSet()->compilerType()==CompilerType::SDCC) {
foreach(const QString& s, SDCCKeywords.keys()) for(auto it=SDCCKeywords.begin();it!=SDCCKeywords.end();++it)
set.insert(s); set.insert(it.key());
} }
#endif #endif
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set); ((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set);

View File

@ -5926,9 +5926,9 @@ void CppParser::internalInvalidateFile(const QString &fileName)
} }
//remove all statements from namespace cache //remove all statements from namespace cache
const QList<QString>& keys=mNamespaces.keys(); for (auto it=mNamespaces.begin();it!=mNamespaces.end();++it) {
for (const QString& key:keys) { QString key = it.key();
PStatementList statements = mNamespaces.value(key); PStatementList statements = it.value();
for (int i=statements->size()-1;i>=0;i--) { for (int i=statements->size()-1;i>=0;i--) {
PStatement statement = statements->at(i); PStatement statement = statements->at(i);
if (statement->fileName == fileName) { if (statement->fileName == fileName) {

View File

@ -781,7 +781,8 @@ void ParsedFileInfo::insertBranch(int level, bool branchTrue)
bool ParsedFileInfo::isLineVisible(int line) const bool ParsedFileInfo::isLineVisible(int line) const
{ {
int lastI=-1; int lastI=-1;
foreach(int i,mBranches.keys()) { for(auto it=mBranches.begin();it!=mBranches.end();++it) {
int i = it.key();
if (line<i) if (line<i)
break; break;
else else