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)
{
foreach(int row, registerValues.keys()){
mRegisterValues[row] = registerValues[row];
for(auto it = registerValues.begin();it!=registerValues.end();++it) {
int row = it.key();
mRegisterValues[row] = it.value();
}
emit dataChanged(createIndex(0,1),
createIndex(mRegisterNames.count()-1,1));

View File

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

View File

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

View File

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