Skip to content

Commit

Permalink
media: Use base::flat_map<>::contains()
Browse files Browse the repository at this point in the history
Use `base::flat_map<>::contains()` instead of `find()` and `count()` for
the better code readability:
* It is less readable and could easily lead another bugs if we mix up
  using `find()`, `count()` and `end()` methods of STL map or chromium
  flat_map.
* Replaced with `contains()` method for `base::flat_map<>`
  (chromium/src/base/containers/flat_map.h) only since C++20 is not
  supported yet for Chromium (go/cpp-chrome).
* Target path: /src/media
* Exception: Did not replace them if the iterator returned by `find
  ()` method is used in the code.

```
autoninja -C out/Default media_unittests
out/Default/media_unittests
```

Bug: 1332591
Change-Id: Idf5374daf26c777672a6c4a672e5b51e5155ed79
Test: All tests passed on an instance of Linux cloudtop
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3696614
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Sangbaek Park <sangbaekpark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1014130}
  • Loading branch information
beback4u authored and Chromium LUCI CQ committed Jun 14, 2022
1 parent da57556 commit 2da0bb0
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions media/audio/audio_output_dispatcher_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ bool AudioOutputDispatcherImpl::StartStream(
AudioOutputStream::AudioSourceCallback* callback,
AudioOutputProxy* stream_proxy) {
DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread());
DCHECK(proxy_to_physical_map_.find(stream_proxy) ==
proxy_to_physical_map_.end());
DCHECK(!proxy_to_physical_map_.contains(stream_proxy));

if (idle_streams_.empty() && !CreateAndOpenStream())
return false;
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/android_cdm_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void AndroidCdmFactory::OnCdmCreated(
const std::string& error_message) {
DVLOG(1) << __func__ << ": creation_id = " << creation_id;

DCHECK(pending_creations_.count(creation_id));
DCHECK(pending_creations_.contains(creation_id));
CdmCreatedCB cdm_created_cb =
std::move(pending_creations_[creation_id].second);
pending_creations_.erase(creation_id);
Expand Down
3 changes: 1 addition & 2 deletions media/base/mime_util_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ void MimeUtil::AddContainerWithCodecs(const std::string& mime_type,
}

bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
return media_format_map_.find(base::ToLowerASCII(mime_type)) !=
media_format_map_.end();
return media_format_map_.contains(base::ToLowerASCII(mime_type));
}

void MimeUtil::SplitCodecs(const std::string& codecs,
Expand Down
4 changes: 2 additions & 2 deletions media/fuchsia/cdm/fuchsia_cdm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void FuchsiaCdm::OnCreateSession(std::unique_ptr<CdmSession> session,
}

session->set_session_id(session_id);
DCHECK(session_map_.find(session_id) == session_map_.end())
DCHECK(!session_map_.contains(session_id))
<< "Duplicated session id " << session_id;
session_map_[session_id] = std::move(session);
}
Expand Down Expand Up @@ -467,7 +467,7 @@ void FuchsiaCdm::OnSessionLoaded(std::unique_ptr<CdmSession> session,
}

std::string session_id = session->session_id();
DCHECK(session_map_.find(session_id) == session_map_.end())
DCHECK(!session_map_.contains(session_id))
<< "Duplicated session id " << session_id;

session_map_.emplace(session_id, std::move(session));
Expand Down
2 changes: 1 addition & 1 deletion media/fuchsia/common/stream_processor_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void StreamProcessorHelper::Process(IoPacket input) {
fidl::Clone(input.format()));
}

DCHECK(input_packets_.find(input.buffer_index()) == input_packets_.end());
DCHECK(!input_packets_.contains(input.buffer_index()));
input_packets_.insert_or_assign(input.buffer_index(), std::move(input));
processor_->QueueInputPacket(std::move(packet));
}
Expand Down
14 changes: 7 additions & 7 deletions media/gpu/mac/vt_video_decode_accelerator_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,8 @@ void VTVideoDecodeAccelerator::DecodeTaskH264(
}

// Record the configuration.
DCHECK(seen_pps_.count(slice_hdr.pic_parameter_set_id));
DCHECK(seen_sps_.count(pps->seq_parameter_set_id));
DCHECK(seen_pps_.contains(slice_hdr.pic_parameter_set_id));
DCHECK(seen_sps_.contains(pps->seq_parameter_set_id));
active_sps_ = seen_sps_[pps->seq_parameter_set_id];
// Note: SPS extension lookup may create an empty entry.
active_spsext_ = seen_spsext_[pps->seq_parameter_set_id];
Expand Down Expand Up @@ -1481,9 +1481,9 @@ void VTVideoDecodeAccelerator::DecodeTaskHEVC(
}

// Record the configuration.
DCHECK(seen_pps_.count(curr_slice_hdr->slice_pic_parameter_set_id));
DCHECK(seen_sps_.count(pps->pps_seq_parameter_set_id));
DCHECK(seen_vps_.count(sps->sps_video_parameter_set_id));
DCHECK(seen_pps_.contains(curr_slice_hdr->slice_pic_parameter_set_id));
DCHECK(seen_sps_.contains(pps->pps_seq_parameter_set_id));
DCHECK(seen_vps_.contains(sps->sps_video_parameter_set_id));
active_vps_ = seen_vps_[sps->sps_video_parameter_set_id];
active_sps_ = seen_sps_[pps->pps_seq_parameter_set_id];
active_pps_ = seen_pps_[curr_slice_hdr->slice_pic_parameter_set_id];
Expand Down Expand Up @@ -1696,7 +1696,7 @@ void VTVideoDecodeAccelerator::DecodeDone(Frame* frame) {

// pending_frames_.erase() will delete |frame|.
int32_t bitstream_id = frame->bitstream_id;
DCHECK_EQ(1u, pending_frames_.count(bitstream_id));
DCHECK(pending_frames_.contains(bitstream_id));

if (state_ == STATE_ERROR || state_ == STATE_DESTROYING) {
// Destroy() handles NotifyEndOfBitstreamBuffer().
Expand Down Expand Up @@ -1809,7 +1809,7 @@ void VTVideoDecodeAccelerator::AssignPictureBuffers(

for (const PictureBuffer& picture : pictures) {
DVLOG(3) << "AssignPictureBuffer(" << picture.id() << ")";
DCHECK(!picture_info_map_.count(picture.id()));
DCHECK(!picture_info_map_.contains(picture.id()));
assigned_picture_ids_.insert(picture.id());
available_picture_ids_.push_back(picture.id());
if (picture.client_texture_ids().empty() &&
Expand Down
2 changes: 1 addition & 1 deletion media/learning/impl/random_tree_trainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct InteriorNode : public Model {

// Add |child| has the node for feature value |v|.
void AddChild(FeatureValue v, std::unique_ptr<Model> child) {
DCHECK_EQ(children_.count(v), 0u);
DCHECK(!children_.contains(v));
children_.emplace(v, std::move(child));
}

Expand Down
5 changes: 3 additions & 2 deletions media/renderers/win/media_foundation_texture_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ ComPtr<ID3D11Texture2D> MediaFoundationTexturePool::AcquireTexture(

void MediaFoundationTexturePool::ReleaseTexture(
const base::UnguessableToken& texture_token) {
if (texture_pool_.count(texture_token) > 0) {
texture_pool_.at(texture_token).texture_in_use_ = false;
auto it = texture_pool_.find(texture_token);
if (it != texture_pool_.end()) {
it->second.texture_in_use_ = false;
}
}

Expand Down

0 comments on commit 2da0bb0

Please sign in to comment.