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_ )
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 )
......
......@@ -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 );
......
......@@ -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 {
......
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