Commit 41e32860 authored by Francois Cartegnie's avatar 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).
parent 30c9622b
...@@ -139,7 +139,7 @@ void EPGItem::setRow( unsigned int i_row_ ) ...@@ -139,7 +139,7 @@ void EPGItem::setRow( unsigned int i_row_ )
updatePos(); 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 ); QDateTime newtime = QDateTime::fromTime_t( data->i_start );
QString newname = qfu( data->psz_name ); QString newname = qfu( data->psz_name );
...@@ -159,7 +159,9 @@ void EPGItem::setData( vlc_epg_event_t *data ) ...@@ -159,7 +159,9 @@ void EPGItem::setData( vlc_epg_event_t *data )
m_shortDescription = newshortdesc; m_shortDescription = newshortdesc;
setDuration( data->i_duration ); setDuration( data->i_duration );
update(); update();
return true;
} }
return false;
} }
void EPGItem::setCurrent( bool b_current ) void EPGItem::setCurrent( bool b_current )
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
int duration() const; int duration() const;
const QString& name() { return m_name; }; const QString& name() { return m_name; };
QString description(); QString description();
void setData( vlc_epg_event_t * ); bool setData( vlc_epg_event_t * );
void setRow( unsigned int ); void setRow( unsigned int );
void setCurrent( bool ); void setCurrent( bool );
void setDuration( int duration ); void setDuration( int duration );
......
...@@ -111,15 +111,18 @@ bool EPGView::hasValidData() ...@@ -111,15 +111,18 @@ bool EPGView::hasValidData()
static void cleanOverlapped( EPGEventByTimeQMap *epgItemByTime, EPGItem *epgItem, QGraphicsScene *scene ) static void cleanOverlapped( EPGEventByTimeQMap *epgItemByTime, EPGItem *epgItem, QGraphicsScene *scene )
{ {
QDateTime epgItemTime = epgItem->start();
QDateTime epgItemTimeEnd = epgItem->end();
/* Clean overlapped programs */ /* Clean overlapped programs */
foreach(const QDateTime existingTimes, epgItemByTime->keys()) 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 ); 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 */ || /* 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() ); epgItemByTime->remove( otherEPGItem->start() );
scene->removeItem( otherEPGItem ); scene->removeItem( otherEPGItem );
...@@ -158,8 +161,8 @@ bool EPGView::addEPGEvent( vlc_epg_event_t *data, QString channelName, bool b_cu ...@@ -158,8 +161,8 @@ bool EPGView::addEPGEvent( vlc_epg_event_t *data, QString channelName, bool b_cu
{ {
/* Update our existing programs */ /* Update our existing programs */
epgItem = epgItemByTime->value( eventStart ); epgItem = epgItemByTime->value( eventStart );
epgItem->setData( data ); /* updates our entry */
epgItem->setCurrent( b_current ); epgItem->setCurrent( b_current );
if ( epgItem->setData( data ) ) /* updates our entry */
cleanOverlapped( epgItemByTime, epgItem, scene() ); cleanOverlapped( epgItemByTime, epgItem, scene() );
mutex.unlock(); mutex.unlock();
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment