From kde-commits Mon Dec 27 09:46:35 2010 From: Volker Krause Date: Mon, 27 Dec 2010 09:46:35 +0000 To: kde-commits Subject: KDE/kdepimlibs/akonadi Message-Id: <20101227094635.3C335AC8AD () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129344323220951 SVN commit 1209556 by vkrause: Re-filter the pending notification when we notice that there is noone listening to one of them. This can happen if the corresponding signal has been disconnected in the meantime, which e.g. the recent optimizations in AgentBase do. Also, change the filtering from O(n²) to O(n) while I was at it. M +17 -11 monitor_p.cpp --- trunk/KDE/kdepimlibs/akonadi/monitor_p.cpp #1209555:1209556 @@ -217,18 +217,20 @@ void MonitorPrivate::cleanOldNotifications() { - foreach ( const NotificationMessage &msg, pipeline ) { - if ( !acceptNotification( msg ) ) { - pipeline.removeOne( msg ); + for ( NotificationMessage::List::iterator it = pipeline.begin(); it != pipeline.end(); ) { + if ( !acceptNotification( *it ) ) + it = pipeline.erase( it ); + else + ++it; } - } - foreach ( const NotificationMessage &msg, pendingNotifications ) { - if ( !acceptNotification( msg ) ) { - pendingNotifications.removeOne( msg ); + for ( NotificationMessage::List::iterator it = pendingNotifications.begin(); it != pendingNotifications.end(); ) { + if ( !acceptNotification( *it ) ) + it = pendingNotifications.erase( it ); + else + ++it; } } -} bool MonitorPrivate::ensureDataAvailable( const NotificationMessage &msg ) { @@ -259,15 +261,19 @@ if ( msg.operation() == NotificationMessage::Move ) destParent = collectionCache.retrieve( msg.parentDestCollection() ); + bool someoneWasListening = false; if ( msg.type() == NotificationMessage::Collection ) { const Collection col = collectionCache.retrieve( msg.uid() ); - return emitCollectionNotification( msg, col, parent, destParent ); + someoneWasListening = emitCollectionNotification( msg, col, parent, destParent ); } else if ( msg.type() == NotificationMessage::Item ) { const Item item = itemCache.retrieve( msg.uid() ); - return emitItemNotification( msg, item, parent, destParent ); + someoneWasListening = emitItemNotification( msg, item, parent, destParent ); } - return false; // nothing emitted + if ( !someoneWasListening ) + cleanOldNotifications(); // probably someone disconnected a signal in the meantime, get rid of the no longer interesting stuff + + return someoneWasListening; } void MonitorPrivate::dataAvailable()