Skip to content

Commit

Permalink
Use find instead of contains for unordered_map
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265920

Reviewed by Don Olmstead.

Build fix for PlayStation.
`map.contains(element)` may read nicely, but `map.find(element) != map.end()` is still a one-liner.
Let's stick to the latter for the moment since it's non-trivial to add a new method to an existing STL container.

* Source/WebCore/platform/graphics/SourceBufferPrivate.cpp:
(WebCore::SourceBufferPrivate::addTrackBuffer):
(WebCore::SourceBufferPrivate::validateInitializationSegment):

Canonical link: https://commits.webkit.org/271589@main
  • Loading branch information
rkirsling committed Dec 6, 2023
1 parent 4425cc9 commit c5de936
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/SourceBufferPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ uint64_t SourceBufferPrivate::totalTrackBufferSizeInBytes() const

void SourceBufferPrivate::addTrackBuffer(TrackID trackId, RefPtr<MediaDescription>&& description)
{
ASSERT(!m_trackBufferMap.contains(trackId));
ASSERT(m_trackBufferMap.find(trackId) == m_trackBufferMap.end());

m_hasAudio = m_hasAudio || description->isAudio();
m_hasVideo = m_hasVideo || description->isVideo();
Expand Down Expand Up @@ -640,21 +640,21 @@ bool SourceBufferPrivate::validateInitializationSegment(const SourceBufferPrivat
// IDs match the ones in the first initialization segment.
if (segment.audioTracks.size() >= 2) {
for (auto& audioTrackInfo : segment.audioTracks) {
if (!m_trackBufferMap.contains(audioTrackInfo.track->id()))
if (m_trackBufferMap.find(audioTrackInfo.track->id()) == m_trackBufferMap.end())
return false;
}
}

if (segment.videoTracks.size() >= 2) {
for (auto& videoTrackInfo : segment.videoTracks) {
if (!m_trackBufferMap.contains(videoTrackInfo.track->id()))
if (m_trackBufferMap.find(videoTrackInfo.track->id()) == m_trackBufferMap.end())
return false;
}
}

if (segment.textTracks.size() >= 2) {
for (auto& textTrackInfo : segment.videoTracks) {
if (!m_trackBufferMap.contains(textTrackInfo.track->id()))
if (m_trackBufferMap.find(textTrackInfo.track->id()) == m_trackBufferMap.end())
return false;
}
}
Expand Down

0 comments on commit c5de936

Please sign in to comment.