opt: smells (#1721)

* opt: remove code smell

for loop should avoid change the iterators

* opt: remove code smell

for loop should avoid change the iterators
This commit is contained in:
xiaoyifang 2024-08-10 10:46:44 +08:00 committed by GitHub
parent 388924033a
commit 65ae8f5030
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -282,20 +282,16 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
bool ignoreDiacritics ) const bool ignoreDiacritics ) const
{ {
if ( !dictIDs.isEmpty() ) { if ( !dictIDs.isEmpty() ) {
QStringList ids = dictIDs; std::vector< sptr< Dictionary::Class > > dicts;
std::vector< sptr< Dictionary::Class > > ftsDicts;
// Find dictionaries by ID's // Find dictionaries by ID's
for ( unsigned x = 0; x < dictionaries.size(); x++ ) { for ( const auto & dictId : dictIDs ) {
for ( QStringList::Iterator it = ids.begin(); it != ids.end(); ++it ) { for ( unsigned x = 0; x < dictionaries.size(); x++ ) {
if ( *it == QString::fromStdString( dictionaries[ x ]->getId() ) ) { if ( dictId == QString::fromStdString( dictionaries[ x ]->getId() ) ) {
ftsDicts.push_back( dictionaries[ x ] ); dicts.push_back( dictionaries[ x ] );
ids.erase( it );
break; break;
} }
} }
if ( ids.isEmpty() )
break;
} }
string header = makeHtmlHeader( word, QString(), true ); string header = makeHtmlHeader( word, QString(), true );
@ -303,7 +299,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
return std::make_shared< ArticleRequest >( word, return std::make_shared< ArticleRequest >( word,
Instances::Group{ groupId, "" }, Instances::Group{ groupId, "" },
contexts, contexts,
ftsDicts, dicts,
header, header,
-1, -1,
true ); true );