]> git.sesse.net Git - vlc/commitdiff
Qt: EPGView: fix performance hit
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 30 Mar 2011 21:43:00 +0000 (23:43 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 30 Mar 2011 22:09:35 +0000 (00:09 +0200)
On every data update, I was cleaning the overlapped entries, and on the
whole list. Apologies for the O(n*n).

modules/gui/qt4/components/epg/EPGItem.cpp
modules/gui/qt4/components/epg/EPGItem.hpp
modules/gui/qt4/components/epg/EPGView.cpp

index 68fc874e93fd41629a7fcc36bc108127a8e38082..e9c761fa463548d08ac5f007279b8f74c86201f1 100644 (file)
@@ -139,7 +139,7 @@ void EPGItem::setRow( unsigned int i_row_ )
     updatePos();
 }
 
-void EPGItem::setData( vlc_epg_event_t *data )
+bool EPGItem::setData( vlc_epg_event_t *data )
 {
     QDateTime newtime = QDateTime::fromTime_t( data->i_start );
     QString newname = qfu( data->psz_name );
@@ -159,7 +159,9 @@ void EPGItem::setData( vlc_epg_event_t *data )
         m_shortDescription = newshortdesc;
         setDuration( data->i_duration );
         update();
+        return true;
     }
+    return false;
 }
 
 void EPGItem::setCurrent( bool b_current )
index 60cc63dc785896e90586679fd0e126c4078e9574..932e419a7381f87c7e688d54a30ee5f2c2feec6b 100644 (file)
@@ -48,7 +48,7 @@ public:
     int duration() const;
     const QString& name() { return m_name; };
     QString description();
-    void setData( vlc_epg_event_t * );
+    bool setData( vlc_epg_event_t * );
     void setRow( unsigned int );
     void setCurrent( bool );
     void setDuration( int duration );
index 4e7e3dd239f43264eedc6db7fef5b18e2c1c39ab..d166a5eb0876acadf4b90009fe61874f27422fd3 100644 (file)
@@ -111,15 +111,18 @@ bool EPGView::hasValidData()
 
 static void cleanOverlapped( EPGEventByTimeQMap *epgItemByTime, EPGItem *epgItem, QGraphicsScene *scene )
 {
+    QDateTime epgItemTime = epgItem->start();
+    QDateTime epgItemTimeEnd = epgItem->end();
     /* Clean overlapped programs */
     foreach(const QDateTime existingTimes, epgItemByTime->keys())
     {
-        if ( existingTimes != epgItem->start() )
+        if ( existingTimes > epgItemTimeEnd ) break; /* Can't overlap later items */
+        if ( existingTimes != epgItemTime )
         {
             EPGItem *otherEPGItem = epgItemByTime->value( existingTimes );
-            if ( otherEPGItem->playsAt( epgItem->start().addSecs( 1 ) )
+            if ( otherEPGItem->playsAt( epgItemTime.addSecs( 1 ) )
                 || /* add/minus one sec because next one can start at prev end min */
-                 otherEPGItem->playsAt( epgItem->end().addSecs( -1 ) ) )
+                 otherEPGItem->playsAt( epgItemTimeEnd.addSecs( -1 ) ) )
             {
                 epgItemByTime->remove( otherEPGItem->start() );
                 scene->removeItem( otherEPGItem );
@@ -158,9 +161,9 @@ bool EPGView::addEPGEvent( vlc_epg_event_t *data, QString channelName, bool b_cu
     {
         /* Update our existing programs */
         epgItem = epgItemByTime->value( eventStart );
-        epgItem->setData( data ); /* updates our entry */
         epgItem->setCurrent( b_current );
-        cleanOverlapped( epgItemByTime, epgItem, scene() );
+        if ( epgItem->setData( data ) ) /* updates our entry */
+            cleanOverlapped( epgItemByTime, epgItem, scene() );
         mutex.unlock();
         return false;
     } else {