[vlc-commits] Qt: EPGView: fix performance hit

Francois Cartegnie git at videolan.org
Thu Mar 31 00:09:39 CEST 2011


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Mar 30 23:43:00 2011 +0200| [41e32860383c388fa252775572d89328d1755e26] | committer: Francois Cartegnie

Qt: EPGView: fix performance hit

On every data update, I was cleaning the overlapped entries, and on the
whole list. Apologies for the O(n*n).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=41e32860383c388fa252775572d89328d1755e26
---

 modules/gui/qt4/components/epg/EPGItem.cpp |    4 +++-
 modules/gui/qt4/components/epg/EPGItem.hpp |    2 +-
 modules/gui/qt4/components/epg/EPGView.cpp |   13 ++++++++-----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/gui/qt4/components/epg/EPGItem.cpp b/modules/gui/qt4/components/epg/EPGItem.cpp
index 68fc874..e9c761f 100644
--- a/modules/gui/qt4/components/epg/EPGItem.cpp
+++ b/modules/gui/qt4/components/epg/EPGItem.cpp
@@ -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 )
diff --git a/modules/gui/qt4/components/epg/EPGItem.hpp b/modules/gui/qt4/components/epg/EPGItem.hpp
index 60cc63d..932e419 100644
--- a/modules/gui/qt4/components/epg/EPGItem.hpp
+++ b/modules/gui/qt4/components/epg/EPGItem.hpp
@@ -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 );
diff --git a/modules/gui/qt4/components/epg/EPGView.cpp b/modules/gui/qt4/components/epg/EPGView.cpp
index 4e7e3dd..d166a5e 100644
--- a/modules/gui/qt4/components/epg/EPGView.cpp
+++ b/modules/gui/qt4/components/epg/EPGView.cpp
@@ -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 {



More information about the vlc-commits mailing list