Skip to content

Commit

Permalink
tidy: Replace x.size() in a boolean context with !x.empty(). (libmythtv)
Browse files Browse the repository at this point in the history
It is not guaranteed that size() is a constant-time function, and it
is generally more efficient and also shows clearer intent to use
empty().

https://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html
  • Loading branch information
linuxdude42 committed Nov 23, 2019
1 parent 1eb530d commit bec6a23
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions mythtv/libs/libmythtv/channelscan/channelimporter.cpp
Expand Up @@ -206,7 +206,7 @@ uint ChannelImporter::DeleteChannels(
AddChanToCopy(transport_copy, transports[i], chan);
}
}
if (transport_copy.m_channels.size() > 0)
if (!transport_copy.m_channels.empty())
off_air_transports.push_back(transport_copy);
}

Expand Down Expand Up @@ -413,29 +413,29 @@ void ChannelImporter::InsertChannels(
}

// List what has been done with each channel
if (updated.size() > 0)
if (!updated.empty())
{
cout << endl << "Updated old channels (" << SimpleCountChannels(updated) << "):" << endl;
cout << FormatChannels(updated).toLatin1().constData() << endl;
}
if (skipped_updates.size() > 0)
if (!skipped_updates.empty())
{
cout << endl << "Skipped old channels (" << SimpleCountChannels(skipped_updates) << "):" << endl;
cout << FormatChannels(skipped_updates).toLatin1().constData() << endl;
}
if (inserted.size() > 0)
if (!inserted.empty())
{
cout << endl << "Inserted new channels (" << SimpleCountChannels(inserted) << "):" << endl;
cout << FormatChannels(inserted).toLatin1().constData() << endl;
}
if (skipped_inserts.size() > 0)
if (!skipped_inserts.empty())
{
cout << endl << "Skipped new channels (" << SimpleCountChannels(skipped_inserts) << "):" << endl;
cout << FormatChannels(skipped_inserts).toLatin1().constData() << endl;
}

// Remaining channels and sum uniques again
if (list.size() > 0)
if (!list.empty())
{
ChannelImporterBasicStats ninfo = CollectStats(list);
ChannelImporterUniquenessStats nstats = CollectUniquenessStats(list, ninfo);
Expand Down Expand Up @@ -680,13 +680,13 @@ ScanDTVTransportList ChannelImporter::InsertChannels(
}
}

if (new_transport.m_channels.size() > 0)
if (!new_transport.m_channels.empty())
next_list.push_back(new_transport);

if (skipped_transport.m_channels.size() > 0)
if (!skipped_transport.m_channels.empty())
skipped_list.push_back(skipped_transport);

if (inserted_transport.m_channels.size() > 0)
if (!inserted_transport.m_channels.empty())
inserted_list.push_back(inserted_transport);
}

Expand Down Expand Up @@ -845,13 +845,13 @@ ScanDTVTransportList ChannelImporter::UpdateChannels(
}
}

if (new_transport.m_channels.size() > 0)
if (!new_transport.m_channels.empty())
next_list.push_back(new_transport);

if (skipped_transport.m_channels.size() > 0)
if (!skipped_transport.m_channels.empty())
skipped_list.push_back(skipped_transport);

if (updated_transport.m_channels.size() > 0)
if (!updated_transport.m_channels.empty())
updated_list.push_back(updated_transport);
}

Expand All @@ -873,7 +873,7 @@ void ChannelImporter::AddChanToCopy(
const ChannelInsertInfo &chan
)
{
if (transport_copy.m_channels.size() == 0)
if (transport_copy.m_channels.empty())
{
transport_copy = transport;
transport_copy.m_channels.clear();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/opengl/mythdrmprimeinterop.cpp
Expand Up @@ -125,7 +125,7 @@ vector<MythVideoTexture*> MythDRMPRIMEInterop::Acquire(MythRenderOpenGL *Context
result = m_openglTextures[id];
}

if (result.size() > 0 ? format_is_yuv(result[0]->m_frameType) : false)
if (!result.empty() ? format_is_yuv(result[0]->m_frameType) : false)
{
// YUV frame - enable picture attributes
if (firstpass)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/opengl/mythnvdecinterop.cpp
Expand Up @@ -379,7 +379,7 @@ void MythNVDECInterop::RotateReferenceFrames(CUdeviceptr Buffer)
return;

// don't retain twice for double rate
if ((m_referenceFrames.size() > 0) && (m_referenceFrames[0] == Buffer))
if (!m_referenceFrames.empty() && (m_referenceFrames[0] == Buffer))
return;

m_referenceFrames.push_front(Buffer);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/opengl/mythvaapidrminterop.cpp
Expand Up @@ -121,7 +121,7 @@ void MythVAAPIInteropDRM::RotateReferenceFrames(AVBufferRef *Buffer)
return;

// don't retain twice for double rate
if ((m_referenceFrames.size() > 0) &&
if (!m_referenceFrames.empty() &&
(static_cast<VASurfaceID>(reinterpret_cast<uintptr_t>(m_referenceFrames[0]->data)) ==
static_cast<VASurfaceID>(reinterpret_cast<uintptr_t>(Buffer->data))))
{
Expand Down Expand Up @@ -478,7 +478,7 @@ bool MythVAAPIInteropDRM::TestPrimeInterop(void)
VADRMtoPRIME(&vadesc, &drmdesc);
vector<MythVideoTexture*> textures = CreateTextures(&drmdesc, m_context, &frame);

if (textures.size() > 0)
if (!textures.empty())
{
s_supported = true;
vector<MythVideoTexture*>::iterator it = textures.begin();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/opengl/mythvdpauinterop.cpp
Expand Up @@ -89,7 +89,7 @@ void MythVDPAUInterop::RotateReferenceFrames(AVBufferRef *Buffer)
return;

// don't retain twice for double rate
if ((m_referenceFrames.size() > 0) &&
if (!m_referenceFrames.empty() &&
(static_cast<VdpVideoSurface>(reinterpret_cast<uintptr_t>(m_referenceFrames[0]->data)) ==
static_cast<VdpVideoSurface>(reinterpret_cast<uintptr_t>(Buffer->data))))
{
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythui/opengl/mythrenderopengl.cpp
Expand Up @@ -1232,10 +1232,10 @@ void MythRenderOpenGL::ReleaseResources(void)
m_openglDebugger = nullptr;
Flush();

if (m_cachedVertices.size())
if (!m_cachedVertices.empty())
LOG(VB_GENERAL, LOG_ERR, LOC + QString(" %1 unexpired vertices").arg(m_cachedVertices.size()));

if (m_cachedVBOS.size())
if (!m_cachedVBOS.empty())
LOG(VB_GENERAL, LOG_ERR, LOC + QString(" %1 unexpired VBOs").arg(m_cachedVertices.size()));
}

Expand Down

0 comments on commit bec6a23

Please sign in to comment.