Replace erase-remove idiom with std::erase and std::erase_if (2)
Bug: webrtc:438403372
Change-Id: I4046ef37985c721d7738680c5c89efc42fda89d0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/404582
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45353}
diff --git a/modules/desktop_capture/cropping_window_capturer_win.cc b/modules/desktop_capture/cropping_window_capturer_win.cc
index 8337714..7ea6c85 100644
--- a/modules/desktop_capture/cropping_window_capturer_win.cc
+++ b/modules/desktop_capture/cropping_window_capturer_win.cc
@@ -191,13 +191,12 @@
return false;
// Filter out windows not visible on current desktop
- auto it = std::remove_if(
- result.begin(), result.end(), [this](const auto& source) {
+ std::erase_if(
+ result, [this](const auto& source) {
HWND hwnd = reinterpret_cast<HWND>(source.id);
return !window_capture_helper_
.IsWindowVisibleOnCurrentDesktop(hwnd);
});
- result.erase(it, result.end());
sources->swap(result);
return true;
diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
index dfcb446..c28fd73 100644
--- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
+++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
@@ -990,9 +990,7 @@
<< " and trying to renegotiate stream parameters";
if (pw_server_version_ >= kDropSingleModifierMinVersion) {
- modifiers_.erase(
- std::remove(modifiers_.begin(), modifiers_.end(), modifier_),
- modifiers_.end());
+ std::erase(modifiers_, modifier_);
} else {
modifiers_.clear();
}
diff --git a/modules/desktop_capture/linux/x11/shared_x_display.cc b/modules/desktop_capture/linux/x11/shared_x_display.cc
index a5781a5..3cb2636 100644
--- a/modules/desktop_capture/linux/x11/shared_x_display.cc
+++ b/modules/desktop_capture/linux/x11/shared_x_display.cc
@@ -63,9 +63,7 @@
if (handlers == event_handlers_.end())
return;
- std::vector<XEventHandler*>::iterator new_end =
- std::remove(handlers->second.begin(), handlers->second.end(), handler);
- handlers->second.erase(new_end, handlers->second.end());
+ std::erase(handlers->second, handler);
// Check if no handlers left for this event.
if (handlers->second.empty())
diff --git a/modules/video_capture/linux/pipewire_session.cc b/modules/video_capture/linux/pipewire_session.cc
index 2eb73a4..1582f85 100644
--- a/modules/video_capture/linux/pipewire_session.cc
+++ b/modules/video_capture/linux/pipewire_session.cc
@@ -178,8 +178,9 @@
static_cast<int32_t>(1.0 * fract[i].num / fract[i].denom),
cap.maxFPS);
}
- } else if (choice == SPA_CHOICE_Range && fract[1].num > 0)
+ } else if (choice == SPA_CHOICE_Range && fract[1].num > 0) {
cap.maxFPS = 1.0 * fract[1].num / fract[1].denom;
+ }
}
}
@@ -393,11 +394,10 @@
RTC_LOG(LS_VERBOSE) << "Enumerating PipeWire camera devices complete.";
// Remove camera devices with no capabilities
- auto it = std::remove_if(that->nodes_.begin(), that->nodes_.end(),
- [](const PipeWireNode::PipeWireNodePtr& node) {
- return node->capabilities().empty();
- });
- that->nodes_.erase(it, that->nodes_.end());
+ std::erase_if(that->nodes_,
+ [](const PipeWireNode::PipeWireNodePtr& node) {
+ return node->capabilities().empty();
+ });
that->Finish(VideoCaptureOptions::Status::SUCCESS);
}
@@ -439,11 +439,9 @@
void PipeWireSession::OnRegistryGlobalRemove(void* data, uint32_t id) {
PipeWireSession* that = static_cast<PipeWireSession*>(data);
- auto it = std::remove_if(that->nodes_.begin(), that->nodes_.end(),
- [id](const PipeWireNode::PipeWireNodePtr& node) {
- return node->id() == id;
- });
- that->nodes_.erase(it, that->nodes_.end());
+ std::erase_if(that->nodes_, [id](const PipeWireNode::PipeWireNodePtr& node) {
+ return node->id() == id;
+ });
}
void PipeWireSession::Finish(VideoCaptureOptions::Status status) {