Skip to content

Commit

Permalink
Optimize CPVRTimerInfoTag. No more copies, just shared pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Mar 1, 2015
1 parent f31bb69 commit 8f32607
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 182 deletions.
48 changes: 14 additions & 34 deletions xbmc/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,21 @@ CFileItem::CFileItem(const CPVRRecordingPtr& record)
FillInMimeType(false);
}

CFileItem::CFileItem(const CPVRTimerInfoTag& timer)
CFileItem::CFileItem(const CPVRTimerInfoTagPtr& timer)
{
assert(timer.get());

Initialize();

m_strPath = timer.Path();
m_bIsFolder = false;
*GetPVRTimerInfoTag() = timer;
SetLabel(timer.Title());
m_strLabel2 = timer.Summary();
m_dateTime = timer.StartAsLocalTime();
m_pvrTimerInfoTag = timer;
m_strPath = timer->Path();
SetLabel(timer->Title());
m_strLabel2 = timer->Summary();
m_dateTime = timer->StartAsLocalTime();

if (!timer.ChannelIcon().empty())
SetIconImage(timer.ChannelIcon());
if (!timer->ChannelIcon().empty())
SetIconImage(timer->ChannelIcon());

FillInMimeType(false);
}
Expand Down Expand Up @@ -236,7 +238,6 @@ CFileItem::CFileItem(const CFileItem& item): CGUIListItem()
{
m_musicInfoTag = NULL;
m_videoInfoTag = NULL;
m_pvrTimerInfoTag = NULL;
m_pictureInfoTag = NULL;
*this = item;
}
Expand Down Expand Up @@ -319,12 +320,10 @@ CFileItem::~CFileItem(void)
{
delete m_musicInfoTag;
delete m_videoInfoTag;
delete m_pvrTimerInfoTag;
delete m_pictureInfoTag;

m_musicInfoTag = NULL;
m_videoInfoTag = NULL;
m_pvrTimerInfoTag = NULL;
m_pictureInfoTag = NULL;
}

Expand Down Expand Up @@ -379,19 +378,10 @@ const CFileItem& CFileItem::operator=(const CFileItem& item)
else
m_pvrRecordingInfoTag.reset();

if (item.HasPVRTimerInfoTag())
{
m_pvrTimerInfoTag = GetPVRTimerInfoTag();
if (m_pvrTimerInfoTag)
*m_pvrTimerInfoTag = *item.m_pvrTimerInfoTag;
}
if (item.m_pvrTimerInfoTag)
m_pvrTimerInfoTag = item.m_pvrTimerInfoTag;
else
{
if (m_pvrTimerInfoTag)
delete m_pvrTimerInfoTag;

m_pvrTimerInfoTag = NULL;
}
m_pvrTimerInfoTag.reset();

if (item.HasPictureInfoTag())
{
Expand Down Expand Up @@ -428,7 +418,6 @@ void CFileItem::Initialize()
{
m_musicInfoTag = NULL;
m_videoInfoTag = NULL;
m_pvrTimerInfoTag = NULL;
m_pictureInfoTag = NULL;
m_bLabelPreformated=false;
m_bIsAlbum = false;
Expand Down Expand Up @@ -471,8 +460,7 @@ void CFileItem::Reset()
m_epgInfoTag.reset();
m_pvrChannelInfoTag.reset();
m_pvrRecordingInfoTag.reset();
delete m_pvrTimerInfoTag;
m_pvrTimerInfoTag=NULL;
m_pvrTimerInfoTag.reset();
delete m_pictureInfoTag;
m_pictureInfoTag=NULL;
m_extrainfo.clear();
Expand Down Expand Up @@ -3142,14 +3130,6 @@ CVideoInfoTag* CFileItem::GetVideoInfoTag()
return m_videoInfoTag;
}

CPVRTimerInfoTag* CFileItem::GetPVRTimerInfoTag()
{
if (!m_pvrTimerInfoTag)
m_pvrTimerInfoTag = new CPVRTimerInfoTag;

return m_pvrTimerInfoTag;
}

CPictureInfoTag* CFileItem::GetPictureInfoTag()
{
if (!m_pictureInfoTag)
Expand Down
9 changes: 4 additions & 5 deletions xbmc/FileItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace PVR
class CPVRTimerInfoTag;
typedef std::shared_ptr<PVR::CPVRRecording> CPVRRecordingPtr;
typedef std::shared_ptr<PVR::CPVRChannel> CPVRChannelPtr;
typedef std::shared_ptr<PVR::CPVRTimerInfoTag> CPVRTimerInfoTagPtr;
}
class CPictureInfoTag;

Expand Down Expand Up @@ -110,7 +111,7 @@ class CFileItem :
CFileItem(const EPG::CEpgInfoTagPtr& tag);
CFileItem(const PVR::CPVRChannelPtr& channel);
CFileItem(const PVR::CPVRRecordingPtr& record);
CFileItem(const PVR::CPVRTimerInfoTag& timer);
CFileItem(const PVR::CPVRTimerInfoTagPtr& timer);
CFileItem(const CMediaSource& share);
virtual ~CFileItem(void);
virtual CGUIListItem *Clone() const { return new CFileItem(*this); };
Expand Down Expand Up @@ -306,9 +307,7 @@ class CFileItem :
return m_pvrTimerInfoTag != NULL;
}

PVR::CPVRTimerInfoTag* GetPVRTimerInfoTag();

inline const PVR::CPVRTimerInfoTag* GetPVRTimerInfoTag() const
inline const PVR::CPVRTimerInfoTagPtr GetPVRTimerInfoTag() const
{
return m_pvrTimerInfoTag;
}
Expand Down Expand Up @@ -495,7 +494,7 @@ class CFileItem :
EPG::CEpgInfoTagPtr m_epgInfoTag;
PVR::CPVRChannelPtr m_pvrChannelInfoTag;
PVR::CPVRRecordingPtr m_pvrRecordingInfoTag;
PVR::CPVRTimerInfoTag * m_pvrTimerInfoTag;
PVR::CPVRTimerInfoTagPtr m_pvrTimerInfoTag;
CPictureInfoTag* m_pictureInfoTag;
bool m_bIsAlbum;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/GUIInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5249,7 +5249,7 @@ bool CGUIInfoManager::GetItemBool(const CGUIListItem *item, int condition) const
}
else if (pItem->HasPVRTimerInfoTag())
{
const CPVRTimerInfoTag *timer = pItem->GetPVRTimerInfoTag();
const CPVRTimerInfoTagPtr timer = pItem->GetPVRTimerInfoTag();
if (timer)
return timer->IsRecording();
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/AddonCallbacksPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void CAddonCallbacksPVR::PVRTransferTimerEntry(void *addonData, const ADDON_HAND
}

/* transfer this entry to the timers container */
CPVRTimerInfoTag transferTimer(*timer, channel, client->GetID());
CPVRTimerInfoTagPtr transferTimer(new CPVRTimerInfoTag(*timer, channel, client->GetID()));
xbmcTimers->UpdateFromClient(transferTimer);
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/epg/EpgSearchFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int EpgSearchFilter::FilterTimers(CFileItemList &results)
if (!fileItem || !fileItem->HasPVRTimerInfoTag())
continue;

CPVRTimerInfoTag *timer = fileItem->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr timer = fileItem->GetPVRTimerInfoTag();
if (!timer)
continue;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/FileItemHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char
if (item->HasPVRRecordingInfoTag())
FillDetails(item->GetPVRRecordingInfoTag().get(), item, fields, object, thumbLoader);
if (item->HasPVRTimerInfoTag())
FillDetails(item->GetPVRTimerInfoTag(), item, fields, object, thumbLoader);
FillDetails(item->GetPVRTimerInfoTag().get(), item, fields, object, thumbLoader);
if (item->HasVideoInfoTag())
FillDetails(item->GetVideoInfoTag(), item, fields, object, thumbLoader);
if (item->HasMusicInfoTag())
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/PVROperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ JSONRPC_STATUS CPVROperations::GetTimerDetails(const std::string &method, ITrans
if (!timer)
return InvalidParams;

HandleFileItem("timerid", false, "timerdetails", CFileItemPtr(new CFileItem(*timer)), parameterObject, parameterObject["properties"], result, false);
HandleFileItem("timerid", false, "timerdetails", CFileItemPtr(new CFileItem(timer)), parameterObject, parameterObject["properties"], result, false);

return OK;
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/pvr/PVRGUIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ void CPVRGUIInfo::UpdateNextTimer(void)
CFileItemPtr tag = g_PVRTimers->GetNextActiveTimer();
if (tag && tag->HasPVRTimerInfoTag())
{
CPVRTimerInfoTag *timer = tag->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr timer = tag->GetPVRTimerInfoTag();
strNextRecordingTitle = StringUtils::Format("%s", timer->Title().c_str());
strNextRecordingChannelName = StringUtils::Format("%s", timer->ChannelName().c_str());
strNextRecordingChannelIcon = StringUtils::Format("%s", timer->ChannelIcon().c_str());
Expand Down Expand Up @@ -833,7 +833,7 @@ void CPVRGUIInfo::UpdateTimersToggle(void)
std::vector<CFileItemPtr> activeTags = g_PVRTimers->GetActiveRecordings();
if (m_iTimerInfoToggleCurrent < activeTags.size() && activeTags.at(m_iTimerInfoToggleCurrent)->HasPVRTimerInfoTag())
{
CPVRTimerInfoTag *tag = activeTags.at(m_iTimerInfoToggleCurrent)->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr tag = activeTags.at(m_iTimerInfoToggleCurrent)->GetPVRTimerInfoTag();
strActiveTimerTitle = StringUtils::Format("%s", tag->Title().c_str());
strActiveTimerChannelName = StringUtils::Format("%s", tag->ChannelName().c_str());
strActiveTimerChannelIcon = StringUtils::Format("%s", tag->ChannelIcon().c_str());
Expand Down
11 changes: 4 additions & 7 deletions xbmc/pvr/PVRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,13 +1454,10 @@ bool CPVRManager::EventOccursOnLocalBackend(const CFileItemPtr& item) const
{
if (item && item->HasPVRTimerInfoTag())
{
CPVRTimerInfoTag* tag = item->GetPVRTimerInfoTag();
if (tag)
{
std::string hostname(m_addons->GetBackendHostnameByClientId(tag->m_iClientId));
if (!hostname.empty() && g_application.getNetwork().IsLocalHost(hostname))
return true;
}
CPVRTimerInfoTagPtr tag(item->GetPVRTimerInfoTag());
std::string hostname(m_addons->GetBackendHostnameByClientId(tag->m_iClientId));
if (!hostname.empty() && g_application.getNetwork().IsLocalHost(hostname))
return true;
}
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ bool CGUIDialogPVRGuideInfo::ActionStartTimer(const CEpgInfoTagPtr &tag)
if (pDialog->IsConfirmed())
{
Close();
CPVRTimerInfoTag *newTimer = CPVRTimerInfoTag::CreateFromEpg(*tag);
CPVRTimerInfoTagPtr newTimer = CPVRTimerInfoTag::CreateFromEpg(tag);
if (newTimer)
{
bReturn = CPVRTimers::AddTimer(*newTimer);
delete newTimer;
bReturn = CPVRTimers::AddTimer(newTimer);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions xbmc/pvr/dialogs/GUIDialogPVRTimerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void CGUIDialogPVRTimerSettings::OnSettingChanged(const CSetting *setting)

CGUIDialogSettingsManualBase::OnSettingChanged(setting);

CPVRTimerInfoTag* tag = m_timerItem->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr tag = m_timerItem->GetPVRTimerInfoTag();
if (tag == NULL)
return;

Expand Down Expand Up @@ -176,7 +176,7 @@ void CGUIDialogPVRTimerSettings::OnSettingAction(const CSetting *setting)

CGUIDialogSettingsManualBase::OnSettingAction(setting);

CPVRTimerInfoTag* tag = m_timerItem->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr tag = m_timerItem->GetPVRTimerInfoTag();
if (tag == NULL)
return;

Expand Down Expand Up @@ -228,7 +228,7 @@ void CGUIDialogPVRTimerSettings::OnSettingAction(const CSetting *setting)

void CGUIDialogPVRTimerSettings::Save()
{
CPVRTimerInfoTag* tag = m_timerItem->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr tag = m_timerItem->GetPVRTimerInfoTag();

// Set the timer's title to the channel name if it's 'New Timer' or empty
if (tag->m_strTitle == g_localizeStrings.Get(19056) || tag->m_strTitle.empty())
Expand Down Expand Up @@ -272,7 +272,7 @@ void CGUIDialogPVRTimerSettings::InitializeSettings()
// add a condition
m_settingsManager->AddCondition("IsTimerDayRepeating", IsTimerDayRepeating);

CPVRTimerInfoTag* tag = m_timerItem->GetPVRTimerInfoTag();
CPVRTimerInfoTagPtr tag = m_timerItem->GetPVRTimerInfoTag();

m_selectedChannelEntry = 0;
m_channelEntries.clear();
Expand Down Expand Up @@ -498,7 +498,7 @@ void CGUIDialogPVRTimerSettings::DaysOptionsFiller(const CSetting *setting, std:
if (dialog == NULL)
return;

const CPVRTimerInfoTag *tag = dialog->m_timerItem->GetPVRTimerInfoTag();
const CPVRTimerInfoTagPtr tag = dialog->m_timerItem->GetPVRTimerInfoTag();
if (tag == NULL)
return;

Expand Down
Loading

0 comments on commit 8f32607

Please sign in to comment.