OSDN Git Service

generic: fix bad usage of mutable iterators
authorIvailo Monev <xakepa10@gmail.com>
Wed, 2 Mar 2022 00:44:40 +0000 (02:44 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 2 Mar 2022 00:45:06 +0000 (02:45 +0200)
most of which could be immutable, fixes crashes when scrolling quickly
trought pages in Okular for example

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
16 files changed:
akregator/plugins/mk4storage/storagemk4impl.cpp
akregator/src/feed.cpp
kget/core/transfergrouphandler.cpp
kget/core/transfertreemodel.cpp
kget/plasma/applet/barapplet/kgetbarapplet.cpp
kget/plasma/applet/piechart/kgetpiechart.cpp
kget/ui/contextmenu.cpp
okular/core/annotations.cpp
okular/core/bookmarkmanager.cpp
okular/core/document.cpp
okular/core/page.cpp
okular/core/textpage.cpp
okular/generators/djvu/kdjvu.cpp
okular/ui/pageview.cpp
okular/ui/pageviewutils.cpp
okular/ui/presentationwidget.cpp

index f2aab5d..6f4cefe 100644 (file)
@@ -150,8 +150,7 @@ bool Akregator::Backend::StorageMK4Impl::autoCommit() const
 bool Akregator::Backend::StorageMK4Impl::close()
 {
     QMap<QString, FeedStorageMK4Impl*>::Iterator it;
-    QMap<QString, FeedStorageMK4Impl*>::Iterator end(d->feeds.end() ) ;
-    for (it = d->feeds.begin(); it != end; ++it)
+    for (it = d->feeds.begin(); it != d->feeds.end(); ++it)
     {
         it.value()->close();
         delete it.value();
@@ -172,8 +171,7 @@ bool Akregator::Backend::StorageMK4Impl::close()
 bool Akregator::Backend::StorageMK4Impl::commit()
 {
     QMap<QString, FeedStorageMK4Impl*>::Iterator it;
-    QMap<QString, FeedStorageMK4Impl*>::Iterator end(d->feeds.end() ) ;
-    for ( it = d->feeds.begin(); it != end; ++it )
+    for ( it = d->feeds.begin(); it != d->feeds.end(); ++it )
         it.value()->commit();
 
     if(d->storage)
@@ -188,8 +186,7 @@ bool Akregator::Backend::StorageMK4Impl::commit()
 bool Akregator::Backend::StorageMK4Impl::rollback()
 {
     QMap<QString, FeedStorageMK4Impl*>::Iterator it;
-    QMap<QString, FeedStorageMK4Impl*>::Iterator end(d->feeds.end() ) ;
-    for ( it = d->feeds.begin(); it != end; ++it )
+    for ( it = d->feeds.begin(); it != d->feeds.end(); ++it )
         it.value()->rollback();
 
     if(d->storage)
index b7a25f3..7b39947 100644 (file)
@@ -577,8 +577,7 @@ void Akregator::Feed::fetch(bool followDiscovery)
     // mark all new as unread
     QList<Article> articles = d->articles.values();
     QList<Article>::Iterator it;
-    QList<Article>::Iterator en = articles.end();
-    for (it = articles.begin(); it != en; ++it)
+    for (it = articles.begin(); it != articles.end(); ++it)
     {
         if ((*it).status() == New)
         {
index 44a977a..e8184fb 100644 (file)
@@ -54,9 +54,8 @@ void TransferGroupHandler::move(QList<TransferHandler *> transfers, TransferHand
         return;
 
     QList<TransferHandler *>::iterator it = transfers.begin();
-    QList<TransferHandler *>::iterator itEnd = transfers.end();
 
-    for( ; it!=itEnd ; ++it )
+    for( ; it!=transfers.end() ; ++it )
     {
         //Move the transfers in the JobQueue
         if(after)
index 1723286..b1fb150 100644 (file)
@@ -227,8 +227,7 @@ void TransferTreeModel::delGroup(TransferGroup * group)
 
     QList<Transfer*> transfers;
     JobQueue::iterator it;
-    JobQueue::iterator itEnd = group->end();
-    for (it = group->begin(); it != itEnd; ++it) {
+    for (it = group->begin(); it != group->end(); ++it) {
         transfers << static_cast<Transfer*>(*it);
     }
     delTransfers(transfers);
@@ -291,8 +290,7 @@ void TransferTreeModel::delTransfers(const QList<Transfer*> &t)
     QHash<TransferGroup*, QList<Transfer*> > groupsTransfer;
     {
         QList<Transfer*>::iterator it;
-        QList<Transfer*>::iterator itEnd = transfers.end();
-        for (it = transfers.begin(); it != itEnd; ) { 
+        for (it = transfers.begin(); it != transfers.end(); ) { 
             TransferModelItem *item = itemFromTransferHandler((*it)->handler());
             if (item) {
                 handlers << (*it)->handler();
@@ -310,8 +308,7 @@ void TransferTreeModel::delTransfers(const QList<Transfer*> &t)
     //remove the items from the model
     {
         QHash<TransferGroup*, QList<TransferModelItem*> >::iterator it;
-        QHash<TransferGroup*, QList<TransferModelItem*> >::iterator itEnd = groups.end();
-        for (it = groups.begin(); it != itEnd; ++it) {
+        for (it = groups.begin(); it != groups.end(); ++it) {
             const int numItems = (*it).count();
             QStandardItem *parentItem = (*it).first()->parent();
             QModelIndex parentIndex = parentItem->index();
@@ -350,8 +347,7 @@ void TransferTreeModel::delTransfers(const QList<Transfer*> &t)
 
     {
         QHash<TransferGroup*, QList<Transfer*> >::iterator it;
-        QHash<TransferGroup*, QList<Transfer*> >::iterator itEnd = groupsTransfer.end();
-        for (it = groupsTransfer.begin(); it != itEnd; ++it) {
+        for (it = groupsTransfer.begin(); it != groupsTransfer.end(); ++it) {
             it.key()->remove(it.value());
         }
     }
index 29f710f..66847bf 100644 (file)
@@ -86,8 +86,7 @@ void KGetBarApplet::Private::removeTransfers(const QList<OrgKdeKgetTransferInter
 {
     // remove the progressbars for the deleted transfers
     QHash<OrgKdeKgetTransferInterface*, Item*>::iterator it;
-    QHash<OrgKdeKgetTransferInterface*, Item*>::iterator itEnd = m_items.end();
-    for (it = m_items.begin(); it != itEnd; ) {
+    for (it = m_items.begin(); it != m_items.end(); ) {
         OrgKdeKgetTransferInterface *transfer = it.key();
         if (transfers.contains(transfer)) {
             Item *item = it.value();
index cb0b373..553a6dd 100644 (file)
@@ -253,8 +253,7 @@ void KGetPieChart::Private::removeTransfers(const QList<OrgKdeKgetTransferInterf
 {
     // remove the progressbars for the deleted transfers
     QHash<OrgKdeKgetTransferInterface*, Item*>::iterator it;
-    QHash<OrgKdeKgetTransferInterface*, Item*>::iterator itEnd = m_items.end();
-    for (it = m_items.begin(); it != itEnd; ) {
+    for (it = m_items.begin(); it != m_items.end(); ) {
         OrgKdeKgetTransferInterface *transfer = it.key();
         if (transfers.contains(transfer)) {
             Item *item = it.value();
index 929bd40..e6f7861 100644 (file)
@@ -33,9 +33,8 @@ KMenu * ContextMenu::createTransferContextMenu(QList<TransferHandler*> transfers
     //bool sameFactory = true;
 
     /*QList<TransferHandler *>::iterator it = transfers.begin();
-    QList<TransferHandler *>::iterator itEnd = transfers.end();
 
-    for(; (it!=itEnd) && (sameFactory) ; ++it)
+    for(; (it!=transfers.end()) && (sameFactory) ; ++it)
     {
         //sameFactory = ( (*it)->m_transfer->factory() == //Port factory() to transferhandler
          //               transfers.first()->m_transfer->factory() );
index c54fb36..106cfaf 100644 (file)
@@ -500,8 +500,8 @@ AnnotationPrivate::~AnnotationPrivate()
     if ( m_revisions.isEmpty() )
         return;
 
-    QList< Annotation::Revision >::iterator it = m_revisions.begin(), end = m_revisions.end();
-    for ( ; it != end; ++it )
+    QList< Annotation::Revision >::iterator it = m_revisions.begin();
+    for ( ; it != m_revisions.end(); ++it )
         delete (*it).annotation();
 }
 
index c568f26..69183f0 100644 (file)
@@ -181,13 +181,13 @@ void BookmarkManager::Private::_o_changed( const QString & groupAddress, const Q
 
     KUrl referurl;
     // first, try to find the bookmark group whom change notification was just received
-    QHash<KUrl, QString>::iterator it = knownFiles.begin(), itEnd = knownFiles.end();
-    for ( ; it != itEnd; ++it )
+    QHash<KUrl, QString>::iterator it = knownFiles.begin();
+    for ( ; it != knownFiles.end(); ++it )
     {
         if ( it.value() == groupAddress )
         {
             referurl = it.key();
-            knownFiles.erase( it );
+            it = knownFiles.erase( it );
             break;
         }
     }
index 1ae5ac4..abe0e40 100644 (file)
@@ -427,13 +427,12 @@ void DocumentPrivate::cleanupPixmapMemory( qulonglong memoryToFree )
 AllocatedPixmap * DocumentPrivate::searchLowestPriorityPixmap( bool unloadableOnly, bool thenRemoveIt, DocumentObserver *observer )
 {
     QList< AllocatedPixmap * >::iterator pIt = m_allocatedPixmaps.begin();
-    QList< AllocatedPixmap * >::iterator pEnd = m_allocatedPixmaps.end();
-    QList< AllocatedPixmap * >::iterator farthestPixmap = pEnd;
+    QList< AllocatedPixmap * >::iterator farthestPixmap = m_allocatedPixmaps.end();
     const int currentViewportPage = (*m_viewportIterator).pageNumber;
 
     /* Find the pixmap that is farthest from the current viewport */
     int maxDistance = -1;
-    while ( pIt != pEnd )
+    while ( pIt != m_allocatedPixmaps.end() )
     {
         const AllocatedPixmap * p = *pIt;
         // Filter by observer
@@ -450,7 +449,7 @@ AllocatedPixmap * DocumentPrivate::searchLowestPriorityPixmap( bool unloadableOn
     }
 
     /* No pixmap to remove */
-    if ( farthestPixmap == pEnd )
+    if ( farthestPixmap == m_allocatedPixmaps.end() )
         return 0;
 
     AllocatedPixmap * selectedPixmap = *farthestPixmap;
@@ -1514,8 +1513,8 @@ void DocumentPrivate::slotGeneratorConfigChanged( const QString& )
 
     // reparse generator config and if something changed clear Pages
     bool configchanged = false;
-    QHash< QString, GeneratorInfo >::iterator it = m_loadedGenerators.begin(), itEnd = m_loadedGenerators.end();
-    for ( ; it != itEnd; ++it )
+    QHash< QString, GeneratorInfo >::iterator it = m_loadedGenerators.begin();
+    for ( ; it != m_loadedGenerators.end(); ++it )
     {
         Okular::ConfigInterface * iface = generatorConfig( it.value() );
         if ( iface )
@@ -2476,8 +2475,7 @@ void Document::removeObserver( DocumentObserver * pObserver )
 
         // [MEM] free observer's allocation descriptors
         QList< AllocatedPixmap * >::iterator aIt = d->m_allocatedPixmaps.begin();
-        QList< AllocatedPixmap * >::iterator aEnd = d->m_allocatedPixmaps.end();
-        while ( aIt != aEnd )
+        while ( aIt != d->m_allocatedPixmaps.end() )
         {
             AllocatedPixmap * p = *aIt;
             if ( p->observer == pObserver )
@@ -2832,8 +2830,8 @@ void Document::requestPixmaps( const QList< PixmapRequest * > & requests, Pixmap
     }
     const bool removeAllPrevious = reqOptions & RemoveAllPrevious;
     d->m_pixmapRequestsMutex.lock();
-    QList< PixmapRequest * >::iterator sIt = d->m_pixmapRequestsStack.begin(), sEnd = d->m_pixmapRequestsStack.end();
-    while ( sIt != sEnd )
+    QList< PixmapRequest * >::iterator sIt = d->m_pixmapRequestsStack.begin();
+    while ( sIt != d->m_pixmapRequestsStack.end() )
     {
         if ( (*sIt)->observer() == requesterObserver
              && ( removeAllPrevious || requestedPages.contains( (*sIt)->pageNumber() ) ) )
@@ -2897,8 +2895,7 @@ void Document::requestPixmaps( const QList< PixmapRequest * > & requests, Pixmap
         {
             // insert in stack sorted by priority
             sIt = d->m_pixmapRequestsStack.begin();
-            sEnd = d->m_pixmapRequestsStack.end();
-            while ( sIt != sEnd && (*sIt)->priority() > request->priority() )
+            while ( sIt != d->m_pixmapRequestsStack.end() && (*sIt)->priority() > request->priority() )
                 ++sIt;
             d->m_pixmapRequestsStack.insert( sIt, request );
         }
@@ -3882,8 +3879,7 @@ void Document::fillConfigDialog( KConfigDialog * dialog )
 
     bool pagesAdded = false;
     QHash< QString, GeneratorInfo >::iterator it = d->m_loadedGenerators.begin();
-    QHash< QString, GeneratorInfo >::iterator itEnd = d->m_loadedGenerators.end();
-    for ( ; it != itEnd; ++it )
+    for ( ; it != d->m_loadedGenerators.end(); ++it )
     {
         Okular::ConfigInterface * iface = d->generatorConfig( it.value() );
         if ( iface )
@@ -4276,8 +4272,7 @@ void DocumentPrivate::requestDone( PixmapRequest * req )
 
     // [MEM] 1.1 find and remove a previous entry for the same page and id
     QList< AllocatedPixmap * >::iterator aIt = m_allocatedPixmaps.begin();
-    QList< AllocatedPixmap * >::iterator aEnd = m_allocatedPixmaps.end();
-    for ( ; aIt != aEnd; ++aIt )
+    for ( ; aIt != m_allocatedPixmaps.end(); ++aIt )
         if ( (*aIt)->page == req->pageNumber() && (*aIt)->observer == req->observer() )
         {
             AllocatedPixmap * p = *aIt;
index cb75043..5104667 100644 (file)
@@ -54,8 +54,8 @@ static const double distanceConsideredEqual = 25; // 5px
 
 static void deleteObjectRects( QList< ObjectRect * >& rects, const QSet<ObjectRect::ObjectType>& which )
 {
-    QList< ObjectRect * >::iterator it = rects.begin(), end = rects.end();
-    for ( ; it != end; )
+    QList< ObjectRect * >::iterator it = rects.begin();
+    for ( ; it != rects.end(); )
         if ( which.contains( (*it)->objectType() ) )
         {
             delete *it;
@@ -654,14 +654,14 @@ bool Page::removeAnnotation( Annotation * annotation )
     if ( !d->m_doc->m_parent->canRemovePageAnnotation(annotation) )
         return false;
 
-    QList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
-    for ( ; aIt != aEnd; ++aIt )
+    QList< Annotation * >::iterator aIt = m_annotations.begin();
+    for ( ; aIt != m_annotations.end(); ++aIt )
     {
         if((*aIt) && (*aIt)->uniqueName()==annotation->uniqueName())
         {
             int rectfound = false;
-            QList< ObjectRect * >::iterator it = m_rects.begin(), end = m_rects.end();
-            for ( ; it != end && !rectfound; ++it )
+            QList< ObjectRect * >::iterator it = m_rects.begin();
+            for ( ; it != m_rects.end() && !rectfound; ++it )
                 if ( ( (*it)->objectType() == ObjectRect::OAnnotation ) && ( (*it)->object() == (*aIt) ) )
                 {
                     delete *it;
@@ -750,8 +750,8 @@ void Page::deleteRects()
 void PagePrivate::deleteHighlights( int s_id )
 {
     // delete highlights by ID
-    QList< HighlightAreaRect* >::iterator it = m_page->m_highlights.begin(), end = m_page->m_highlights.end();
-    while ( it != end )
+    QList< HighlightAreaRect* >::iterator it = m_page->m_highlights.begin();
+    while ( it != m_page->m_highlights.end() )
     {
         HighlightAreaRect* highlight = *it;
         if ( s_id == -1 || highlight->s_id == s_id )
index 9d2c070..2e706de 100644 (file)
@@ -1296,10 +1296,10 @@ QList< QPair<WordsWithCharacters, QRect> > makeAndSortLines(const WordsWithChara
     qSort(words.begin(),words.end(),compareTinyTextEntityY);
 
     // Step 2
-    QList<WordWithCharacters>::Iterator it = words.begin(), itEnd = words.end();
+    QList<WordWithCharacters>::Iterator it = words.begin();
 
     //for every non-space texts(characters/words) in the textList
-    for( ; it != itEnd ; it++)
+    for( ; it != words.end() ; it++)
     {
         const QRect elementArea = (*it).area().roundedGeometry(pageWidth,pageHeight);
         bool found = false;
index 302a69b..0cd6daa 100644 (file)
@@ -754,8 +754,8 @@ void KDjVu::closeFile()
     qDeleteAll( d->m_pages );
     d->m_pages.clear();
     // releasing the djvu pages
-    QVector<ddjvu_page_t *>::Iterator it = d->m_pages_cache.begin(), itEnd = d->m_pages_cache.end();
-    for ( ; it != itEnd; ++it )
+    QVector<ddjvu_page_t *>::Iterator it = d->m_pages_cache.begin();
+    for ( ; it != d->m_pages_cache.end(); ++it )
         ddjvu_page_release( *it );
     d->m_pages_cache.clear();
     // clearing the image cache
@@ -910,8 +910,8 @@ QImage KDjVu::image( int page, int width, int height, int rotation )
     if ( d->m_cacheEnabled )
     {
     bool found = false;
-    QList<ImageCacheItem*>::Iterator it = d->mImgCache.begin(), itEnd = d->mImgCache.end();
-    for ( ; ( it != itEnd ) && !found; ++it )
+    QList<ImageCacheItem*>::Iterator it = d->mImgCache.begin();
+    for ( ; ( it != d->mImgCache.end() ) && !found; ++it )
     {
         ImageCacheItem* cur = *it;
         if ( ( cur->page == page ) &&
index 8584688..01eae64 100644 (file)
@@ -705,8 +705,7 @@ void PageView::openAnnotationWindow( Okular::Annotation * annotation, int pageNu
 void PageView::slotAnnotationWindowDestroyed( QObject * window )
 {
     QHash< Okular::Annotation*, AnnotWindow * >::Iterator it = d->m_annowindows.begin();
-    QHash< Okular::Annotation*, AnnotWindow * >::Iterator itEnd = d->m_annowindows.end();
-    while ( it != itEnd )
+    while ( it != d->m_annowindows.end() )
     {
         if ( it.value() == window )
         {
index cc95098..7c94f6c 100644 (file)
@@ -50,8 +50,8 @@ PageViewItem::PageViewItem( const Okular::Page * page )
 
 PageViewItem::~PageViewItem()
 {
-    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin(), itEnd = m_formWidgets.end();
-    for ( ; it != itEnd; ++it )
+    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin();
+    for ( ; it != m_formWidgets.end(); ++it )
         delete *it;
     qDeleteAll( m_videoWidgets );
 }
@@ -162,8 +162,8 @@ void PageViewItem::moveTo( int x, int y )
     m_croppedGeometry.moveTop( y );
     m_uncroppedGeometry.moveLeft( qRound( x - m_crop.left * m_uncroppedGeometry.width() ) );
     m_uncroppedGeometry.moveTop( qRound( y - m_crop.top * m_uncroppedGeometry.height() ) );
-    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin(), itEnd = m_formWidgets.end();
-    for ( ; it != itEnd; ++it )
+    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin();
+    for ( ; it != m_formWidgets.end(); ++it )
     {
         Okular::NormalizedRect r = (*it)->rect();
         (*it)->moveTo(
@@ -199,8 +199,8 @@ bool PageViewItem::setFormWidgetsVisible( bool visible )
         return false;
 
     bool somehadfocus = false;
-    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin(), itEnd = m_formWidgets.end();
-    for ( ; it != itEnd; ++it )
+    QHash<int, FormWidgetIface*>::iterator it = m_formWidgets.begin();
+    for ( ; it != m_formWidgets.end(); ++it )
     {
         bool hadfocus = (*it)->setVisibility( visible );
         somehadfocus = somehadfocus || hadfocus;
@@ -519,8 +519,8 @@ void PageViewToolBar::setItems( const QList<AnnotationToolItem> &items )
     // delete buttons if already present
     if ( !d->buttons.isEmpty() )
     {
-        QList< ToolBarButton * >::iterator it = d->buttons.begin(), end = d->buttons.end();
-        for ( ; it != end; ++it )
+        QList< ToolBarButton * >::iterator it = d->buttons.begin();
+        for ( ; it != d->buttons.end(); ++it )
             delete *it;
         d->buttons.clear();
     }
index 0d3c71c..bc17cda 100644 (file)
@@ -293,8 +293,8 @@ PresentationWidget::~PresentationWidget()
     delete m_drawingEngine;
 
     // delete frames
-    QVector< PresentationFrame * >::iterator fIt = m_frames.begin(), fEnd = m_frames.end();
-    for ( ; fIt != fEnd; ++fIt )
+    QVector< PresentationFrame * >::iterator fIt = m_frames.begin();
+    for ( ; fIt != m_frames.end(); ++fIt )
         delete *fIt;
 }
 
@@ -307,8 +307,8 @@ void PresentationWidget::notifySetup( const QVector< Okular::Page * > & pageSet,
         return;
 
     // delete previous frames (if any (shouldn't be))
-    QVector< PresentationFrame * >::iterator fIt = m_frames.begin(), fEnd = m_frames.end();
-    for ( ; fIt != fEnd; ++fIt )
+    QVector< PresentationFrame * >::iterator fIt = m_frames.begin();
+    for ( ; fIt != m_frames.end(); ++fIt )
         delete *fIt;
     if ( !m_frames.isEmpty() )
         kWarning() << "Frames setup changed while a Presentation is in progress.";