performance: Prefer prefix ++/-- operators for non-primitive types.

more detail check https://hownot2code.com/2016/06/30/use-a-prefix-increment-operator-i-in-iterators-instead-of-a-postfix-i-operator/
This commit is contained in:
xiaoyifang 2022-02-16 21:47:03 +08:00
parent 1131cc6b1e
commit 570c75e920
4 changed files with 9 additions and 9 deletions

View file

@ -3616,7 +3616,7 @@ void MainWindow::on_saveArticle_triggered()
// Pull and save resources to files // Pull and save resources to files
for ( vector< pair< QUrl, QString > >::const_iterator i = downloadResources.begin(); for ( vector< pair< QUrl, QString > >::const_iterator i = downloadResources.begin();
i != downloadResources.end(); i++ ) i != downloadResources.end(); ++i )
{ {
ResourceToSaveHandler * handler = view->saveResource( i->first, i->second ); ResourceToSaveHandler * handler = view->saveResource( i->first, i->second );
if( !handler->isEmpty() ) if( !handler->isEmpty() )

View file

@ -168,7 +168,7 @@ bool MdictParser::readNextHeadWordIndex( MdictParser::HeadWordIndex & headWordIn
return false; return false;
headWordIndex = splitHeadWordBlock( decompressed ); headWordIndex = splitHeadWordBlock( decompressed );
headWordBlockInfosIter_++; ++headWordBlockInfosIter_;
return true; return true;
} }

12
mdx.cc
View file

@ -842,7 +842,7 @@ void MddResourceRequest::run()
catch ( File::exCantOpen & ) catch ( File::exCantOpen & )
{ {
for ( vector< sptr< IndexedMdd > >::const_iterator i = dict.mddResources.begin(); for ( vector< sptr< IndexedMdd > >::const_iterator i = dict.mddResources.begin();
i != dict.mddResources.end(); i++ ) i != dict.mddResources.end(); ++i )
{ {
sptr< IndexedMdd > mddResource = *i; sptr< IndexedMdd > mddResource = *i;
if ( mddResource->loadFile( resourceName, data ) ) if ( mddResource->loadFile( resourceName, data ) )
@ -1436,7 +1436,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
catch ( File::exCantOpen & ) catch ( File::exCantOpen & )
{ {
for ( vector< sptr< IndexedMdd > >::const_iterator i = mddResources.begin(); for ( vector< sptr< IndexedMdd > >::const_iterator i = mddResources.begin();
i != mddResources.end(); i++ ) i != mddResources.end(); ++i )
{ {
sptr< IndexedMdd > mddResource = *i; sptr< IndexedMdd > mddResource = *i;
if ( mddResource->loadFile( resourceName, data ) ) if ( mddResource->loadFile( resourceName, data ) )
@ -1611,7 +1611,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
{ {
vector< sptr< Dictionary::Class > > dictionaries; vector< sptr< Dictionary::Class > > dictionaries;
for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); i++ ) for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i )
{ {
// Skip files with the extensions different to .mdx to speed up the // Skip files with the extensions different to .mdx to speed up the
// scanning // scanning
@ -1641,7 +1641,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
initializing.indexingDictionary( title ); initializing.indexingDictionary( title );
for ( vector< string >::const_iterator mddIter = dictFiles.begin() + 1; for ( vector< string >::const_iterator mddIter = dictFiles.begin() + 1;
mddIter != dictFiles.end(); mddIter++ ) mddIter != dictFiles.end(); ++mddIter )
{ {
if ( File::exists( *mddIter ) ) if ( File::exists( *mddIter ) )
{ {
@ -1740,7 +1740,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idxHeader.styleSheetCount = styleSheets.size(); idxHeader.styleSheetCount = styleSheets.size();
for ( MdictParser::StyleSheets::const_iterator iter = styleSheets.begin(); for ( MdictParser::StyleSheets::const_iterator iter = styleSheets.begin();
iter != styleSheets.end(); iter++ ) iter != styleSheets.end(); ++iter )
{ {
string styleBegin( iter->second.first.toUtf8().constData() ); string styleBegin( iter->second.first.toUtf8().constData() );
string styleEnd( iter->second.second.toUtf8().constData() ); string styleEnd( iter->second.second.toUtf8().constData() );
@ -1771,7 +1771,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Build index info for each mdd file // Build index info for each mdd file
vector< IndexInfo > mddIndexInfos; vector< IndexInfo > mddIndexInfos;
for ( vector< sptr< IndexedWords > >::const_iterator mddIndexIter = mddIndices.begin(); for ( vector< sptr< IndexedWords > >::const_iterator mddIndexIter = mddIndices.begin();
mddIndexIter != mddIndices.end(); mddIndexIter++ ) mddIndexIter != mddIndices.end(); ++mddIndexIter )
{ {
IndexInfo resourceIdxInfo = BtreeIndexing::buildIndex( *( *mddIndexIter ), idx ); IndexInfo resourceIdxInfo = BtreeIndexing::buildIndex( *( *mddIndexIter ), idx );
mddIndexInfos.push_back( resourceIdxInfo ); mddIndexInfos.push_back( resourceIdxInfo );

View file

@ -112,7 +112,7 @@ unsigned int ProcessWrapper::findProcess(const char *name, unsigned int pid_skip
QDir pd("/proc"); QDir pd("/proc");
QFileInfoList list = pd.entryInfoList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); QFileInfoList list = pd.entryInfoList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
QFileInfoList::iterator it, it_end = list.end(); QFileInfoList::iterator it, it_end = list.end();
for (it = list.begin(); it != it_end; it++) for (it = list.begin(); it != it_end; ++it)
{ {
const QFileInfo &fi = *it; const QFileInfo &fi = *it;
if (fi.baseName().at(0).isDigit()) { if (fi.baseName().at(0).isDigit()) {