From: Francois Cartegnie Date: Wed, 30 Mar 2011 21:43:00 +0000 (+0200) Subject: Qt: EPGView: fix performance hit X-Git-Tag: 1.2.0-pre1~3277 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=41e32860383c388fa252775572d89328d1755e26;p=vlc 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). --- diff --git a/modules/gui/qt4/components/epg/EPGItem.cpp b/modules/gui/qt4/components/epg/EPGItem.cpp index 68fc874e93..e9c761fa46 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 60cc63dc78..932e419a73 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 4e7e3dd239..d166a5eb08 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 {