refactor: use std::ranges whenever possible (#10584)

This commit is contained in:
Kamikadze 2025-05-30 18:25:59 +05:00 committed by GitHub
parent 9bf1b49144
commit 9190443d95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
50 changed files with 137 additions and 146 deletions

View file

@ -268,7 +268,7 @@ wl_client* CWLSurfaceResource::client() {
}
void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) != m_enteredOutputs.end())
if (std::ranges::find(m_enteredOutputs, monitor) != m_enteredOutputs.end())
return;
if UNLIKELY (!PROTO::outputs.contains(monitor->m_name)) {
@ -295,7 +295,7 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
}
void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if UNLIKELY (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) == m_enteredOutputs.end())
if UNLIKELY (std::ranges::find(m_enteredOutputs, monitor) == m_enteredOutputs.end())
return;
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client);

View file

@ -171,7 +171,7 @@ void CWLDataSourceResource::accepted(const std::string& mime) {
return;
}
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) {
if (std::ranges::find(m_mimeTypes, mime) == m_mimeTypes.end()) {
LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAccepted with non-existent mime");
return;
}
@ -184,7 +184,7 @@ std::vector<std::string> CWLDataSourceResource::mimes() {
}
void CWLDataSourceResource::send(const std::string& mime, CFileDescriptor fd) {
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) {
if (std::ranges::find(m_mimeTypes, mime) == m_mimeTypes.end()) {
LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAskSend with non-existent mime");
return;
}
@ -424,7 +424,7 @@ SP<IDataDevice> CWLDataDeviceProtocol::dataDeviceForClient(wl_client* c) {
return g_pXWayland->m_wm->getDataDevice();
#endif
auto it = std::find_if(m_devices.begin(), m_devices.end(), [c](const auto& e) { return e->client() == c; });
auto it = std::ranges::find_if(m_devices, [c](const auto& e) { return e->client() == c; });
if (it == m_devices.end())
return nullptr;
return *it;

View file

@ -204,10 +204,10 @@ void CWLPointerResource::sendButton(uint32_t timeMs, uint32_t button, wl_pointer
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) == m_pressedButtons.end()) {
if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::ranges::find(m_pressedButtons, button) == m_pressedButtons.end()) {
LOGM(ERR, "sendButton release on a non-pressed button");
return;
} else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) != m_pressedButtons.end()) {
} else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::ranges::find(m_pressedButtons, button) != m_pressedButtons.end()) {
LOGM(ERR, "sendButton press on a non-pressed button");
return;
}

View file

@ -137,7 +137,7 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
return;
}
if UNLIKELY (std::find(PROTO::shm->m_shmFormats.begin(), PROTO::shm->m_shmFormats.end(), fmt) == PROTO::shm->m_shmFormats.end()) {
if UNLIKELY (std::ranges::find(PROTO::shm->m_shmFormats, fmt) == PROTO::shm->m_shmFormats.end()) {
r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid");
return;
}

View file

@ -30,7 +30,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL
std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; });
auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF);
auto it = std::ranges::find(m_parent->m_subsurfaces, SURF);
if (it == m_parent->m_subsurfaces.end()) {
LOGM(ERR, "Invalid surface reference in placeAbove, likely parent");
@ -43,7 +43,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL
m_parent->m_subsurfaces.emplace_back(m_self);
}
std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
});
m_resource->setPlaceBelow([this](CWlSubsurface* r, wl_resource* surf) {
@ -61,7 +61,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL
std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; });
auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF);
auto it = std::ranges::find(m_parent->m_subsurfaces, SURF);
if (it == m_parent->m_subsurfaces.end()) {
LOGM(ERR, "Invalid surface reference in placeBelow, likely parent");
@ -74,7 +74,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL
m_parent->m_subsurfaces.emplace_back(m_self);
}
std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
});
m_listeners.commitSurface = m_surface->m_events.commit.registerListener([this](std::any d) {
@ -116,8 +116,7 @@ Vector2D CWLSubsurfaceResource::posRelativeToParent() {
// surfaces we've visited and if we hit a surface we've visited we bail out.
std::vector<SP<CWLSurfaceResource>> surfacesVisited;
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE &&
std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && std::ranges::find_if(surfacesVisited, [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
surfacesVisited.emplace_back(surf);
auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock();
pos += subsurface->m_position;
@ -134,8 +133,7 @@ SP<CWLSurfaceResource> CWLSubsurfaceResource::t1Parent() {
SP<CWLSurfaceResource> surf = m_parent.lock();
std::vector<SP<CWLSurfaceResource>> surfacesVisited;
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE &&
std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && std::ranges::find_if(surfacesVisited, [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
surfacesVisited.emplace_back(surf);
auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock();
surf = subsurface->m_parent.lock();