From b7a3c4526990d6601ff2cac748ff860cda6bc16d Mon Sep 17 00:00:00 2001 From: vaxerski Date: Fri, 17 Jan 2025 18:21:34 +0100 Subject: [PATCH] core: add LIKELY and UNLIKELY macros helps the compiler optimize --- src/devices/VirtualPointer.cpp | 2 +- src/macros.hpp | 3 ++ src/protocols/AlphaModifier.cpp | 4 +- src/protocols/CTMControl.cpp | 8 +-- src/protocols/ColorManagement.cpp | 32 ++++++------ src/protocols/CursorShape.cpp | 2 +- src/protocols/DRMLease.cpp | 16 +++--- src/protocols/DRMSyncobj.cpp | 18 +++---- src/protocols/DataDeviceWlr.cpp | 16 +++--- src/protocols/FocusGrab.cpp | 14 +++--- src/protocols/ForeignToplevel.cpp | 20 ++++---- src/protocols/ForeignToplevelWlr.cpp | 70 +++++++++++++-------------- src/protocols/FractionalScale.cpp | 2 +- src/protocols/FrogColorManagement.cpp | 10 ++-- src/protocols/GammaControl.cpp | 20 ++++---- src/protocols/GlobalShortcuts.cpp | 8 +-- src/protocols/HyprlandSurface.cpp | 8 +-- src/protocols/IdleNotify.cpp | 4 +- src/protocols/InputMethodV2.cpp | 16 +++--- src/protocols/LayerShell.cpp | 8 +-- src/protocols/LinuxDMABUF.cpp | 26 +++++----- src/protocols/MesaDRM.cpp | 6 +-- src/protocols/OutputManagement.cpp | 22 ++++----- src/protocols/OutputPower.cpp | 6 +-- src/protocols/PointerConstraints.cpp | 12 ++--- src/protocols/PointerGestures.cpp | 12 ++--- src/protocols/PresentationTime.cpp | 8 +-- src/protocols/PrimarySelection.cpp | 16 +++--- src/protocols/RelativePointer.cpp | 4 +- src/protocols/Screencopy.cpp | 17 +++---- src/protocols/SecurityContext.cpp | 26 +++++----- src/protocols/ServerDecorationKDE.cpp | 4 +- src/protocols/SessionLock.cpp | 8 +-- src/protocols/ShortcutsInhibit.cpp | 6 +-- src/protocols/SinglePixel.cpp | 8 +-- src/protocols/Tablet.cpp | 28 +++++------ src/protocols/TearingControl.cpp | 4 +- src/protocols/TextInputV1.cpp | 6 +-- src/protocols/TextInputV3.cpp | 4 +- src/protocols/ToplevelExport.cpp | 29 ++++++----- src/protocols/Viewporter.cpp | 16 +++--- src/protocols/VirtualKeyboard.cpp | 14 +++--- src/protocols/VirtualPointer.cpp | 10 ++-- src/protocols/WaylandProtocol.cpp | 2 +- src/protocols/XDGActivation.cpp | 12 ++--- src/protocols/XDGDecoration.cpp | 6 +-- src/protocols/XDGDialog.cpp | 14 +++--- src/protocols/XDGOutput.cpp | 10 ++-- src/protocols/XDGShell.cpp | 34 ++++++------- src/protocols/XWaylandShell.cpp | 8 +-- src/protocols/core/Compositor.cpp | 34 ++++++------- src/protocols/core/DataDevice.cpp | 18 +++---- src/protocols/core/Output.cpp | 10 ++-- src/protocols/core/Seat.cpp | 16 +++--- src/protocols/core/Shm.cpp | 32 ++++++------ src/protocols/core/Subcompositor.cpp | 14 +++--- src/protocols/types/DMABuffer.cpp | 6 +-- src/protocols/types/WLBuffer.cpp | 2 +- 58 files changed, 395 insertions(+), 396 deletions(-) diff --git a/src/devices/VirtualPointer.cpp b/src/devices/VirtualPointer.cpp index 514c8c32..7cfb0631 100644 --- a/src/devices/VirtualPointer.cpp +++ b/src/devices/VirtualPointer.cpp @@ -11,7 +11,7 @@ SP CVirtualPointer::create(SP resour } CVirtualPointer::CVirtualPointer(SP resource) : pointer(resource) { - if (!resource->good()) + if UNLIKELY (!resource->good()) return; listeners.destroy = pointer->events.destroy.registerListener([this](std::any d) { diff --git a/src/macros.hpp b/src/macros.hpp index 08c17952..0a3be8bc 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -114,3 +114,6 @@ namespace Aquamarine { \ class name; \ } + +#define UNLIKELY(expr) (expr) [[unlikely]] +#define LIKELY(expr) (expr) [[likely]] diff --git a/src/protocols/AlphaModifier.cpp b/src/protocols/AlphaModifier.cpp index d695b58f..dc32bb8c 100644 --- a/src/protocols/AlphaModifier.cpp +++ b/src/protocols/AlphaModifier.cpp @@ -15,7 +15,7 @@ bool CAlphaModifier::good() { void CAlphaModifier::setResource(SP resource) { m_pResource = std::move(resource); - if (!m_pResource->resource()) + if UNLIKELY (!m_pResource->resource()) return; m_pResource->setDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); }); @@ -98,7 +98,7 @@ void CAlphaModifierProtocol::getSurface(CWpAlphaModifierV1* manager, uint32_t id .first->second.get(); } - if (!alphaModifier->good()) { + if UNLIKELY (!alphaModifier->good()) { manager->noMemory(); m_mAlphaModifiers.erase(surface); } diff --git a/src/protocols/CTMControl.cpp b/src/protocols/CTMControl.cpp index 91e05ac4..91f4501f 100644 --- a/src/protocols/CTMControl.cpp +++ b/src/protocols/CTMControl.cpp @@ -7,7 +7,7 @@ #include "../helpers/Monitor.hpp" CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); }); @@ -17,12 +17,12 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SPmonitor.lock(); - if (!PMONITOR) + if UNLIKELY (!PMONITOR) return; // ?!?! const std::array MAT = {wl_fixed_to_double(mat0), wl_fixed_to_double(mat1), wl_fixed_to_double(mat2), wl_fixed_to_double(mat3), wl_fixed_to_double(mat4), @@ -72,7 +72,7 @@ void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uin const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/ColorManagement.cpp b/src/protocols/ColorManagement.cpp index a76e13c0..c2814361 100644 --- a/src/protocols/ColorManagement.cpp +++ b/src/protocols/ColorManagement.cpp @@ -2,7 +2,7 @@ #include "Compositor.hpp" CColorManager::CColorManager(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->sendSupportedFeature(XX_COLOR_MANAGER_V4_FEATURE_PARAMETRIC); @@ -38,7 +38,7 @@ CColorManager::CColorManager(SP resource_) : resource(resourc const auto RESOURCE = PROTO::colorManagement->m_vOutputs.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vOutputs.pop_back(); return; @@ -63,7 +63,7 @@ CColorManager::CColorManager(SP resource_) : resource(resourc const auto RESOURCE = PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared(makeShared(r->client(), r->version(), id), SURF)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vSurfaces.pop_back(); return; @@ -86,7 +86,7 @@ CColorManager::CColorManager(SP resource_) : resource(resourc const auto RESOURCE = PROTO::colorManagement->m_vFeedbackSurfaces.emplace_back( makeShared(makeShared(r->client(), r->version(), id), SURF)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vFeedbackSurfaces.pop_back(); return; @@ -104,7 +104,7 @@ CColorManager::CColorManager(SP resource_) : resource(resourc const auto RESOURCE = PROTO::colorManagement->m_vParametricCreators.emplace_back( makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vParametricCreators.pop_back(); return; @@ -121,7 +121,7 @@ bool CColorManager::good() { } CColorManagementOutput::CColorManagementOutput(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -137,7 +137,7 @@ CColorManagementOutput::CColorManagementOutput(SP re const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back( makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vImageDescriptions.pop_back(); return; @@ -160,7 +160,7 @@ CColorManagementSurface::CColorManagementSurface(SP surface_ } CColorManagementSurface::CColorManagementSurface(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -242,7 +242,7 @@ bool CColorManagementSurface::needsHdrMetadataUpdate() { CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -269,7 +269,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SPm_vImageDescriptions.emplace_back( makeShared(makeShared(r->client(), r->version(), id), true)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vImageDescriptions.pop_back(); return; @@ -293,7 +293,7 @@ wl_client* CColorManagementFeedbackSurface::client() { } CColorManagementParametricCreator::CColorManagementParametricCreator(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; // pClient = resource->client(); @@ -318,7 +318,7 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SPm_vImageDescriptions.emplace_back( makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::colorManagement->m_vImageDescriptions.pop_back(); return; @@ -465,7 +465,7 @@ wl_client* CColorManagementParametricCreator::client() { CColorManagementImageDescription::CColorManagementImageDescription(SP resource_, bool allowGetInformation) : m_resource(resource_), m_allowGetInformation(allowGetInformation) { - if (!good()) + if UNLIKELY (!good()) return; pClient = m_resource->client(); @@ -482,7 +482,7 @@ CColorManagementImageDescription::CColorManagementImageDescription(SP(makeShared(r->client(), r->version(), id), settings); - if (!RESOURCE->good()) + if UNLIKELY (!RESOURCE->good()) r->noMemory(); // CColorManagementImageDescriptionInfo should send everything in the constructor and be ready for destroying at this point @@ -504,7 +504,7 @@ SP CColorManagementImageDescription::resource() { CColorManagementImageDescriptionInfo::CColorManagementImageDescriptionInfo(SP resource_, const SImageDescription& settings_) : m_resource(resource_), settings(settings_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = m_resource->client(); @@ -549,7 +549,7 @@ CColorManagementProtocol::CColorManagementProtocol(const wl_interface* iface, co void CColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/CursorShape.cpp b/src/protocols/CursorShape.cpp index 233a5df9..429d604f 100644 --- a/src/protocols/CursorShape.cpp +++ b/src/protocols/CursorShape.cpp @@ -41,7 +41,7 @@ void CCursorShapeProtocol::createCursorShapeDevice(CWpCursorShapeManagerV1* pMgr } void CCursorShapeProtocol::onSetShape(CWpCursorShapeDeviceV1* pMgr, uint32_t serial, wpCursorShapeDeviceV1Shape shape) { - if ((uint32_t)shape == 0 || (uint32_t)shape > CURSOR_SHAPE_NAMES.size()) { + if UNLIKELY ((uint32_t)shape == 0 || (uint32_t)shape > CURSOR_SHAPE_NAMES.size()) { pMgr->error(WP_CURSOR_SHAPE_DEVICE_V1_ERROR_INVALID_SHAPE, "The shape is invalid"); return; } diff --git a/src/protocols/DRMLease.cpp b/src/protocols/DRMLease.cpp index 4ab46a46..fce1e345 100644 --- a/src/protocols/DRMLease.cpp +++ b/src/protocols/DRMLease.cpp @@ -6,7 +6,7 @@ #include CDRMLeaseResource::CDRMLeaseResource(SP resource_, SP request) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); }); @@ -79,7 +79,7 @@ CDRMLeaseResource::~CDRMLeaseResource() { } CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpDrmLeaseRequestV1* r) { PROTO::lease->destroyResource(this); }); @@ -109,7 +109,7 @@ CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP reso } auto RESOURCE = makeShared(makeShared(resource->client(), resource->version(), id), self.lock()); - if (!RESOURCE) { + if UNLIKELY (!RESOURCE) { resource->noMemory(); return; } @@ -131,7 +131,7 @@ SP CDRMLeaseConnectorResource::fromResource(wl_resou } CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); }); @@ -160,7 +160,7 @@ void CDRMLeaseConnectorResource::sendData() { } CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); }); @@ -168,7 +168,7 @@ CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP resourc resource->setCreateLeaseRequest([this](CWpDrmLeaseDeviceV1* r, uint32_t id) { auto RESOURCE = makeShared(makeShared(resource->client(), resource->version(), id)); - if (!RESOURCE) { + if UNLIKELY (!RESOURCE) { resource->noMemory(); return; } @@ -209,7 +209,7 @@ void CDRMLeaseDeviceResource::sendConnector(PHLMONITOR monitor) { return; auto RESOURCE = makeShared(makeShared(resource->client(), resource->version(), 0), monitor); - if (!RESOURCE) { + if UNLIKELY (!RESOURCE) { resource->noMemory(); return; } @@ -262,7 +262,7 @@ CDRMLeaseProtocol::CDRMLeaseProtocol(const wl_interface* iface, const int& ver, void CDRMLeaseProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/DRMSyncobj.cpp b/src/protocols/DRMSyncobj.cpp index 1da4baaf..ce598385 100644 --- a/src/protocols/DRMSyncobj.cpp +++ b/src/protocols/DRMSyncobj.cpp @@ -8,7 +8,7 @@ #include CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -104,7 +104,7 @@ bool CDRMSyncobjSurfaceResource::good() { } CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(SP resource_, int fd_) : fd(fd_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -135,31 +135,31 @@ bool CDRMSyncobjTimelineResource::good() { } CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); }); resource->setDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); }); resource->setGetSurface([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, wl_resource* surf) { - if (!surf) { + if UNLIKELY (!surf) { resource->error(-1, "Invalid surface"); return; } auto SURF = CWLSurfaceResource::fromResource(surf); - if (!SURF) { + if UNLIKELY (!SURF) { resource->error(-1, "Invalid surface (2)"); return; } - if (SURF->syncobj) { + if UNLIKELY (SURF->syncobj) { resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_SURFACE_EXISTS, "Surface already has a syncobj attached"); return; } auto RESOURCE = makeShared(makeShared(resource->client(), resource->version(), id), SURF); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); return; } @@ -172,7 +172,7 @@ CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SPsetImportTimeline([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, int32_t fd) { auto RESOURCE = makeShared(makeShared(resource->client(), resource->version(), id), fd); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); return; } @@ -195,7 +195,7 @@ CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& v void CDRMSyncobjProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/DataDeviceWlr.cpp b/src/protocols/DataDeviceWlr.cpp index d8103d11..71ee1c4a 100644 --- a/src/protocols/DataDeviceWlr.cpp +++ b/src/protocols/DataDeviceWlr.cpp @@ -4,7 +4,7 @@ #include "core/Seat.hpp" CWLRDataOffer::CWLRDataOffer(SP resource_, SP source_) : source(source_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); }); @@ -34,7 +34,7 @@ bool CWLRDataOffer::good() { } void CWLRDataOffer::sendData() { - if (!source) + if UNLIKELY (!source) return; for (auto const& m : source->mimes()) { @@ -43,7 +43,7 @@ void CWLRDataOffer::sendData() { } CWLRDataSource::CWLRDataSource(SP resource_, SP device_) : device(device_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -104,7 +104,7 @@ void CWLRDataSource::error(uint32_t code, const std::string& msg) { } CWLRDataDevice::CWLRDataDevice(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -173,7 +173,7 @@ void CWLRDataDevice::sendPrimarySelection(SP selection) { } CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); }); @@ -182,7 +182,7 @@ CWLRDataControlManagerResource::CWLRDataControlManagerResource(SPsetGetDataDevice([this](CZwlrDataControlManagerV1* r, uint32_t id, wl_resource* seat) { const auto RESOURCE = PROTO::dataWlr->m_vDevices.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::dataWlr->m_vDevices.pop_back(); return; @@ -208,7 +208,7 @@ CWLRDataControlManagerResource::CWLRDataControlManagerResource(SPm_vSources.emplace_back(makeShared(makeShared(r->client(), r->version(), id), device.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::dataWlr->m_vSources.pop_back(); return; @@ -236,7 +236,7 @@ CDataDeviceWLRProtocol::CDataDeviceWLRProtocol(const wl_interface* iface, const void CDataDeviceWLRProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/FocusGrab.cpp b/src/protocols/FocusGrab.cpp index aff232e4..ee30343f 100644 --- a/src/protocols/FocusGrab.cpp +++ b/src/protocols/FocusGrab.cpp @@ -17,7 +17,7 @@ CFocusGrabSurfaceState::~CFocusGrabSurfaceState() { } CFocusGrab::CFocusGrab(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; grab = makeShared(); @@ -63,9 +63,8 @@ void CFocusGrab::finish(bool sendCleared) { if (m_bGrabActive) { m_bGrabActive = false; - if (g_pSeatManager->seatGrab == grab) { + if (g_pSeatManager->seatGrab == grab) g_pSeatManager->setGrab(nullptr); - } grab->clear(); m_mSurfaces.clear(); @@ -77,17 +76,16 @@ void CFocusGrab::finish(bool sendCleared) { void CFocusGrab::addSurface(SP surface) { auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [surface](const auto& e) { return e.first == surface; }); - if (iter == m_mSurfaces.end()) { + if (iter == m_mSurfaces.end()) m_mSurfaces.emplace(surface, std::make_unique(this, surface)); - } } void CFocusGrab::removeSurface(SP surface) { auto iter = m_mSurfaces.find(surface); if (iter != m_mSurfaces.end()) { - if (iter->second->state == CFocusGrabSurfaceState::PendingAddition) { + if (iter->second->state == CFocusGrabSurfaceState::PendingAddition) m_mSurfaces.erase(iter); - } else + else iter->second->state = CFocusGrabSurfaceState::PendingRemoval; } } @@ -172,7 +170,7 @@ void CFocusGrabProtocol::onCreateGrab(CHyprlandFocusGrabManagerV1* pMgr, uint32_ m_vGrabs.push_back(std::make_unique(makeShared(pMgr->client(), pMgr->version(), id))); const auto RESOURCE = m_vGrabs.back().get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vGrabs.pop_back(); } diff --git a/src/protocols/ForeignToplevel.cpp b/src/protocols/ForeignToplevel.cpp index f6513a1d..6880164f 100644 --- a/src/protocols/ForeignToplevel.cpp +++ b/src/protocols/ForeignToplevel.cpp @@ -3,7 +3,7 @@ #include "../managers/HookSystemManager.hpp" CForeignToplevelHandle::CForeignToplevelHandle(SP resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); }); @@ -19,7 +19,7 @@ PHLWINDOW CForeignToplevelHandle::window() { } CForeignToplevelList::CForeignToplevelList(SP resource_) : resource(resource_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); }); @@ -40,7 +40,7 @@ CForeignToplevelList::CForeignToplevelList(SP resourc } void CForeignToplevelList::onMap(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto NEWHANDLE = PROTO::foreignToplevel->m_vHandles.emplace_back( @@ -72,11 +72,11 @@ SP CForeignToplevelList::handleForWindow(PHLWINDOW pWind } void CForeignToplevelList::onTitle(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->resource->sendTitle(pWindow->m_szTitle.c_str()); @@ -84,11 +84,11 @@ void CForeignToplevelList::onTitle(PHLWINDOW pWindow) { } void CForeignToplevelList::onClass(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->resource->sendAppId(pWindow->m_szClass.c_str()); @@ -96,11 +96,11 @@ void CForeignToplevelList::onClass(PHLWINDOW pWindow) { } void CForeignToplevelList::onUnmap(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H) + if UNLIKELY (!H) return; H->resource->sendClosed(); @@ -149,7 +149,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co void CForeignToplevelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(std::make_unique(makeShared(client, ver, id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { LOGM(ERR, "Couldn't create a foreign list"); wl_client_post_no_memory(client); m_vManagers.pop_back(); diff --git a/src/protocols/ForeignToplevelWlr.cpp b/src/protocols/ForeignToplevelWlr.cpp index 45ef3f93..e18f6e23 100644 --- a/src/protocols/ForeignToplevelWlr.cpp +++ b/src/protocols/ForeignToplevelWlr.cpp @@ -6,7 +6,7 @@ #include "../managers/HookSystemManager.hpp" CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setOnDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); }); @@ -15,7 +15,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetActivate([this](CZwlrForeignToplevelHandleV1* p, wl_resource* seat) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; // these requests bypass the config'd stuff cuz it's usually like @@ -26,13 +26,13 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetSetFullscreen([this](CZwlrForeignToplevelHandleV1* p, wl_resource* output) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; - if (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN) + if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN) return; - if (!PWINDOW->m_bIsMapped) { + if UNLIKELY (!PWINDOW->m_bIsMapped) { PWINDOW->m_bWantsInitialFullscreen = true; return; } @@ -57,10 +57,10 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetUnsetFullscreen([this](CZwlrForeignToplevelHandleV1* p) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; - if (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN) + if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN) return; g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_FULLSCREEN, false); @@ -69,13 +69,13 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetSetMaximized([this](CZwlrForeignToplevelHandleV1* p) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; - if (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE) + if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE) return; - if (!PWINDOW->m_bIsMapped) { + if UNLIKELY (!PWINDOW->m_bIsMapped) { PWINDOW->m_bWantsInitialFullscreen = true; return; } @@ -86,10 +86,10 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetUnsetMaximized([this](CZwlrForeignToplevelHandleV1* p) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; - if (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE) + if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE) return; g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_MAXIMIZED, false); @@ -98,7 +98,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SPsetClose([this](CZwlrForeignToplevelHandleV1* p) { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW) + if UNLIKELY (!PWINDOW) return; g_pCompositor->closeWindow(PWINDOW); @@ -126,14 +126,14 @@ void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) { if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->szName)) { const auto OLDRESOURCE = PROTO::outputs.at(PLASTMONITOR->szName)->outputResourceFrom(CLIENT); - if (OLDRESOURCE) + if LIKELY (OLDRESOURCE) resource->sendOutputLeave(OLDRESOURCE->getResource()->resource()); } if (PROTO::outputs.contains(pMonitor->szName)) { const auto NEWRESOURCE = PROTO::outputs.at(pMonitor->szName)->outputResourceFrom(CLIENT); - if (NEWRESOURCE) + if LIKELY (NEWRESOURCE) resource->sendOutputEnter(NEWRESOURCE->getResource()->resource()); } @@ -143,7 +143,7 @@ void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) { void CForeignToplevelHandleWlr::sendState() { const auto PWINDOW = pWindow.lock(); - if (!PWINDOW || !PWINDOW->m_pWorkspace || !PWINDOW->m_bIsMapped) + if UNLIKELY (!PWINDOW || !PWINDOW->m_pWorkspace || !PWINDOW->m_bIsMapped) return; wl_array state; @@ -168,7 +168,7 @@ void CForeignToplevelHandleWlr::sendState() { } CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP resource_) : resource(resource_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setOnDestroy([this](CZwlrForeignToplevelManagerV1* h) { PROTO::foreignToplevelWlr->onManagerResourceDestroy(this); }); @@ -191,13 +191,13 @@ CForeignToplevelWlrManager::CForeignToplevelWlrManager(SPm_vHandles.emplace_back( makeShared(makeShared(resource->client(), resource->version(), 0), pWindow)); - if (!NEWHANDLE->good()) { + if UNLIKELY (!NEWHANDLE->good()) { LOGM(ERR, "Couldn't create a foreign handle"); resource->noMemory(); PROTO::foreignToplevelWlr->m_vHandles.pop_back(); @@ -208,7 +208,7 @@ void CForeignToplevelWlrManager::onMap(PHLWINDOW pWindow) { resource->sendToplevel(NEWHANDLE->resource.get()); NEWHANDLE->resource->sendAppId(pWindow->m_szClass.c_str()); NEWHANDLE->resource->sendTitle(pWindow->m_szTitle.c_str()); - if (const auto PMONITOR = pWindow->m_pMonitor.lock(); PMONITOR) + if LIKELY (const auto PMONITOR = pWindow->m_pMonitor.lock(); PMONITOR) NEWHANDLE->sendMonitor(PMONITOR); NEWHANDLE->sendState(); NEWHANDLE->resource->sendDone(); @@ -223,11 +223,11 @@ SP CForeignToplevelWlrManager::handleForWindow(PHLWIN } void CForeignToplevelWlrManager::onTitle(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->resource->sendTitle(pWindow->m_szTitle.c_str()); @@ -235,11 +235,11 @@ void CForeignToplevelWlrManager::onTitle(PHLWINDOW pWindow) { } void CForeignToplevelWlrManager::onClass(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->resource->sendAppId(pWindow->m_szClass.c_str()); @@ -247,11 +247,11 @@ void CForeignToplevelWlrManager::onClass(PHLWINDOW pWindow) { } void CForeignToplevelWlrManager::onUnmap(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H) + if UNLIKELY (!H) return; H->resource->sendClosed(); @@ -260,16 +260,16 @@ void CForeignToplevelWlrManager::onUnmap(PHLWINDOW pWindow) { } void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; const auto PMONITOR = pWindow->m_pMonitor.lock(); - if (!PMONITOR) + if UNLIKELY (!PMONITOR) return; H->sendMonitor(PMONITOR); @@ -277,11 +277,11 @@ void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) { } void CForeignToplevelWlrManager::onFullscreen(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->sendState(); @@ -289,10 +289,10 @@ void CForeignToplevelWlrManager::onFullscreen(PHLWINDOW pWindow) { } void CForeignToplevelWlrManager::onNewFocus(PHLWINDOW pWindow) { - if (finished) + if UNLIKELY (finished) return; - if (const auto HOLD = handleForWindow(lastFocus.lock()); HOLD) { + if LIKELY (const auto HOLD = handleForWindow(lastFocus.lock()); HOLD) { HOLD->sendState(); HOLD->resource->sendDone(); } @@ -300,7 +300,7 @@ void CForeignToplevelWlrManager::onNewFocus(PHLWINDOW pWindow) { lastFocus = pWindow; const auto H = handleForWindow(pWindow); - if (!H || H->closed) + if UNLIKELY (!H || H->closed) return; H->sendState(); @@ -378,7 +378,7 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa void CForeignToplevelWlrProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(std::make_unique(makeShared(client, ver, id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { LOGM(ERR, "Couldn't create a foreign list"); wl_client_post_no_memory(client); m_vManagers.pop_back(); diff --git a/src/protocols/FractionalScale.cpp b/src/protocols/FractionalScale.cpp index d8010eac..d1e0a604 100644 --- a/src/protocols/FractionalScale.cpp +++ b/src/protocols/FractionalScale.cpp @@ -35,7 +35,7 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1* const auto PADDON = m_mAddons.emplace(surface, std::make_unique(makeShared(pMgr->client(), pMgr->version(), id), surface)).first->second.get(); - if (!PADDON->good()) { + if UNLIKELY (!PADDON->good()) { m_mAddons.erase(surface); pMgr->noMemory(); return; diff --git a/src/protocols/FrogColorManagement.cpp b/src/protocols/FrogColorManagement.cpp index f27af5c8..cb2eed12 100644 --- a/src/protocols/FrogColorManagement.cpp +++ b/src/protocols/FrogColorManagement.cpp @@ -3,7 +3,7 @@ #include "protocols/core/Subcompositor.hpp" CFrogColorManager::CFrogColorManager(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([](CFrogColorManagementFactoryV1* r) { LOGM(TRACE, "Destroy frog_color_management at {:x} (generated default)", (uintptr_t)r); }); @@ -24,7 +24,7 @@ CFrogColorManager::CFrogColorManager(SP resource_ const auto RESOURCE = PROTO::frogColorManagement->m_vSurfaces.emplace_back( makeShared(makeShared(r->client(), r->version(), id), SURF)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::frogColorManagement->m_vSurfaces.pop_back(); return; @@ -39,14 +39,14 @@ bool CFrogColorManager::good() { } CFrogColorManagementSurface::CFrogColorManagementSurface(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); if (!surface->colorManagement.valid()) { const auto RESOURCE = PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared(surface_)); - if (!RESOURCE) { + if UNLIKELY (!RESOURCE) { resource->noMemory(); PROTO::colorManagement->m_vSurfaces.pop_back(); return; @@ -141,7 +141,7 @@ CFrogColorManagementProtocol::CFrogColorManagementProtocol(const wl_interface* i void CFrogColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/GammaControl.cpp b/src/protocols/GammaControl.cpp index b0da29a2..299d7717 100644 --- a/src/protocols/GammaControl.cpp +++ b/src/protocols/GammaControl.cpp @@ -6,12 +6,12 @@ #include "../render/Renderer.hpp" CGammaControl::CGammaControl(SP resource_, wl_resource* output) : resource(resource_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; auto OUTPUTRES = CWLOutputResource::fromResource(output); - if (!OUTPUTRES) { + if UNLIKELY (!OUTPUTRES) { LOGM(ERR, "No output in CGammaControl"); resource->sendFailed(); return; @@ -19,14 +19,14 @@ CGammaControl::CGammaControl(SP resource_, wl_resource* out pMonitor = OUTPUTRES->monitor; - if (!pMonitor || !pMonitor->output) { + if UNLIKELY (!pMonitor || !pMonitor->output) { LOGM(ERR, "No CMonitor"); resource->sendFailed(); return; } for (auto const& g : PROTO::gamma->m_vGammaControllers) { - if (g->pMonitor == pMonitor) { + if UNLIKELY (g->pMonitor == pMonitor) { resource->sendFailed(); return; } @@ -34,7 +34,7 @@ CGammaControl::CGammaControl(SP resource_, wl_resource* out gammaSize = pMonitor->output->getGammaSize(); - if (gammaSize <= 0) { + if UNLIKELY (gammaSize <= 0) { LOGM(ERR, "Output {} doesn't support gamma", pMonitor->szName); resource->sendFailed(); return; @@ -46,7 +46,7 @@ CGammaControl::CGammaControl(SP resource_, wl_resource* out resource->setOnDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); }); resource->setSetGamma([this](CZwlrGammaControlV1* gamma, int32_t fd) { - if (!pMonitor) { + if UNLIKELY (!pMonitor) { LOGM(ERR, "setGamma for a dead monitor"); resource->sendFailed(); close(fd); @@ -56,14 +56,14 @@ CGammaControl::CGammaControl(SP resource_, wl_resource* out LOGM(LOG, "setGamma for {}", pMonitor->szName); int fdFlags = fcntl(fd, F_GETFL, 0); - if (fdFlags < 0) { + if UNLIKELY (fdFlags < 0) { LOGM(ERR, "Failed to get fd flags"); resource->sendFailed(); close(fd); return; } - if (fcntl(fd, F_SETFL, fdFlags | O_NONBLOCK) < 0) { + if UNLIKELY (fcntl(fd, F_SETFL, fdFlags | O_NONBLOCK) < 0) { LOGM(ERR, "Failed to set fd flags"); resource->sendFailed(); close(fd); @@ -126,7 +126,7 @@ bool CGammaControl::good() { } void CGammaControl::applyToMonitor() { - if (!pMonitor || !pMonitor->output) + if UNLIKELY (!pMonitor || !pMonitor->output) return; // ?? LOGM(LOG, "setting to monitor {}", pMonitor->szName); @@ -179,7 +179,7 @@ void CGammaControlProtocol::onGetGammaControl(CZwlrGammaControlManagerV1* pMgr, const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vGammaControllers.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id), output)).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vGammaControllers.pop_back(); return; diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp index ca67f063..6fac2d7f 100644 --- a/src/protocols/GlobalShortcuts.cpp +++ b/src/protocols/GlobalShortcuts.cpp @@ -1,7 +1,7 @@ #include "GlobalShortcuts.hpp" CShortcutClient::CShortcutClient(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); }); @@ -9,7 +9,7 @@ CShortcutClient::CShortcutClient(SP resource_ resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description, const char* trigger_description) { - if (PROTO::globalShortcuts->isTaken(id, app_id)) { + if UNLIKELY (PROTO::globalShortcuts->isTaken(id, app_id)) { resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken"); return; } @@ -20,7 +20,7 @@ CShortcutClient::CShortcutClient(SP resource_ PSHORTCUT->appid = app_id; PSHORTCUT->shortcut = shortcut; - if (!PSHORTCUT->resource->resource()) { + if UNLIKELY (!PSHORTCUT->resource->resource()) { PSHORTCUT->resource->noMemory(); shortcuts.pop_back(); return; @@ -41,7 +41,7 @@ CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, co void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESROUCE = m_vClients.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESROUCE->good()) { + if UNLIKELY (!RESROUCE->good()) { wl_client_post_no_memory(client); m_vClients.pop_back(); return; diff --git a/src/protocols/HyprlandSurface.cpp b/src/protocols/HyprlandSurface.cpp index ce6fc77a..bcf4905c 100644 --- a/src/protocols/HyprlandSurface.cpp +++ b/src/protocols/HyprlandSurface.cpp @@ -15,20 +15,20 @@ bool CHyprlandSurface::good() const { void CHyprlandSurface::setResource(SP resource) { m_pResource = std::move(resource); - if (!m_pResource->resource()) + if UNLIKELY (!m_pResource->resource()) return; m_pResource->setDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); }); m_pResource->setOnDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); }); m_pResource->setSetOpacity([this](CHyprlandSurfaceV1* resource, uint32_t opacity) { - if (!m_pSurface) { + if UNLIKELY (!m_pSurface) { m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE, "set_opacity called for destroyed wl_surface"); return; } auto fOpacity = wl_fixed_to_double(opacity); - if (fOpacity < 0.0 || fOpacity > 1.0) { + if UNLIKELY (fOpacity < 0.0 || fOpacity > 1.0) { m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE, "set_opacity called with an opacity value larger than 1.0 or smaller than 0.0."); return; } @@ -104,7 +104,7 @@ void CHyprlandSurfaceProtocol::getSurface(CHyprlandSurfaceManagerV1* manager, ui .first->second.get(); } - if (!hyprlandSurface->good()) { + if UNLIKELY (!hyprlandSurface->good()) { manager->noMemory(); m_mSurfaces.erase(surface); } diff --git a/src/protocols/IdleNotify.cpp b/src/protocols/IdleNotify.cpp index 3517a62d..85a9f8e2 100644 --- a/src/protocols/IdleNotify.cpp +++ b/src/protocols/IdleNotify.cpp @@ -11,7 +11,7 @@ static int onTimer(SP self, void* data) { } CExtIdleNotification::CExtIdleNotification(SP resource_, uint32_t timeoutMs_) : resource(resource_), timeoutMs(timeoutMs_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); }); @@ -78,7 +78,7 @@ void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t i const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vNotifications.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id), timeout)).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vNotifications.pop_back(); return; diff --git a/src/protocols/InputMethodV2.cpp b/src/protocols/InputMethodV2.cpp index 5fd1e893..cf777f45 100644 --- a/src/protocols/InputMethodV2.cpp +++ b/src/protocols/InputMethodV2.cpp @@ -7,7 +7,7 @@ #include CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP resource_, SP owner_) : resource(resource_), owner(owner_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); }); @@ -34,13 +34,13 @@ void CInputMethodKeyboardGrabV2::sendKeyboardData(SP keyboard) { pLastKeyboard = keyboard; int keymapFD = allocateSHMFile(keyboard->xkbKeymapString.length() + 1); - if (keymapFD < 0) { + if UNLIKELY (keymapFD < 0) { LOGM(ERR, "Failed to create a keymap file for keyboard grab"); return; } void* data = mmap(nullptr, keyboard->xkbKeymapString.length() + 1, PROT_READ | PROT_WRITE, MAP_SHARED, keymapFD, 0); - if (data == MAP_FAILED) { + if UNLIKELY (data == MAP_FAILED) { LOGM(ERR, "Failed to mmap a keymap file for keyboard grab"); close(keymapFD); return; @@ -83,7 +83,7 @@ wl_client* CInputMethodKeyboardGrabV2::client() { } CInputMethodPopupV2::CInputMethodPopupV2(SP resource_, SP owner_, SP surface) : resource(resource_), owner(owner_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); }); @@ -149,7 +149,7 @@ void CInputMethodV2::SState::reset() { } CInputMethodV2::CInputMethodV2(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CZwpInputMethodV2* r) { @@ -189,7 +189,7 @@ CInputMethodV2::CInputMethodV2(SP resource_) : resource(resou const auto RESOURCE = PROTO::ime->m_vPopups.emplace_back( makeShared(makeShared(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surface))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::ime->m_vPopups.pop_back(); return; @@ -206,7 +206,7 @@ CInputMethodV2::CInputMethodV2(SP resource_) : resource(resou const auto RESOURCE = PROTO::ime->m_vGrabs.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::ime->m_vGrabs.pop_back(); return; @@ -360,7 +360,7 @@ void CInputMethodV2Protocol::destroyResource(CInputMethodV2* ime) { void CInputMethodV2Protocol::onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id) { const auto RESOURCE = m_vIMEs.emplace_back(makeShared(makeShared(mgr->client(), mgr->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { mgr->noMemory(); m_vIMEs.pop_back(); return; diff --git a/src/protocols/LayerShell.cpp b/src/protocols/LayerShell.cpp index 0777149f..82d00a30 100644 --- a/src/protocols/LayerShell.cpp +++ b/src/protocols/LayerShell.cpp @@ -18,7 +18,7 @@ void CLayerShellResource::SState::reset() { CLayerShellResource::CLayerShellResource(SP resource_, SP surf_, std::string namespace_, PHLMONITOR pMonitor, zwlrLayerShellV1Layer layer) : layerNamespace(namespace_), surface(surf_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; current.layer = layer; @@ -223,19 +223,19 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id const auto PMONITOR = output ? CWLOutputResource::fromResource(output)->monitor.lock() : nullptr; auto SURF = CWLSurfaceResource::fromResource(surface); - if (!SURF) { + if UNLIKELY (!SURF) { pMgr->error(-1, "Invalid surface"); return; } - if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { + if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { pMgr->error(-1, "Surface already has a different role"); return; } const auto RESOURCE = m_vLayers.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id), SURF, namespace_, PMONITOR, layer)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vLayers.pop_back(); return; diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp index 24b8f62c..85f7b1c6 100644 --- a/src/protocols/LinuxDMABUF.cpp +++ b/src/protocols/LinuxDMABUF.cpp @@ -126,7 +126,7 @@ bool CLinuxDMABuffer::good() { } CLinuxDMABBUFParamsResource::CLinuxDMABBUFParamsResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); }); @@ -208,12 +208,12 @@ bool CLinuxDMABBUFParamsResource::good() { void CLinuxDMABBUFParamsResource::create(uint32_t id) { used = true; - if (!verify()) { + if UNLIKELY (!verify()) { LOGM(ERR, "Failed creating a dmabuf: verify() said no"); return; // if verify failed, we errored the resource. } - if (!commence()) { + if UNLIKELY (!commence()) { LOGM(ERR, "Failed creating a dmabuf: commence() said no"); resource->sendFailed(); return; @@ -226,7 +226,7 @@ void CLinuxDMABBUFParamsResource::create(uint32_t id) { auto buf = PROTO::linuxDma->m_vBuffers.emplace_back(makeShared(id, resource->client(), *attrs)); - if (!buf->good() || !buf->buffer->success) { + if UNLIKELY (!buf->good() || !buf->buffer->success) { resource->sendFailed(); return; } @@ -259,12 +259,12 @@ bool CLinuxDMABBUFParamsResource::commence() { } bool CLinuxDMABBUFParamsResource::verify() { - if (attrs->planes <= 0) { + if UNLIKELY (attrs->planes <= 0) { resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added"); return false; } - if (attrs->fds.at(0) < 0) { + if UNLIKELY (attrs->fds.at(0) < 0) { resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0"); return false; } @@ -282,7 +282,7 @@ bool CLinuxDMABBUFParamsResource::verify() { } } - if (attrs->size.x < 1 || attrs->size.y < 1) { + if UNLIKELY (attrs->size.x < 1 || attrs->size.y < 1) { resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1"); return false; } @@ -300,7 +300,7 @@ bool CLinuxDMABBUFParamsResource::verify() { } CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); }); @@ -355,7 +355,7 @@ void CLinuxDMABUFFeedbackResource::sendDefaultFeedback() { } CLinuxDMABUFResource::CLinuxDMABUFResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); }); @@ -365,7 +365,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP resource_) : re const auto RESOURCE = PROTO::linuxDma->m_vFeedbacks.emplace_back(makeShared(makeShared(r->client(), r->version(), id), nullptr)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::linuxDma->m_vFeedbacks.pop_back(); return; @@ -376,7 +376,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP resource_) : re const auto RESOURCE = PROTO::linuxDma->m_vFeedbacks.emplace_back( makeShared(makeShared(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::linuxDma->m_vFeedbacks.pop_back(); return; @@ -386,7 +386,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP resource_) : re resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) { const auto RESOURCE = PROTO::linuxDma->m_vParams.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::linuxDma->m_vParams.pop_back(); return; @@ -535,7 +535,7 @@ CLinuxDMABufV1Protocol::~CLinuxDMABufV1Protocol() { void CLinuxDMABufV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/MesaDRM.cpp b/src/protocols/MesaDRM.cpp index 41536988..caa539a2 100644 --- a/src/protocols/MesaDRM.cpp +++ b/src/protocols/MesaDRM.cpp @@ -35,7 +35,7 @@ bool CMesaDRMBufferResource::good() { } CMesaDRMResource::CMesaDRMResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlDrm* r) { PROTO::mesaDRM->destroyResource(this); }); @@ -87,7 +87,7 @@ CMesaDRMResource::CMesaDRMResource(SP resource_) : resource(resource_) { const auto RESOURCE = PROTO::mesaDRM->m_vBuffers.emplace_back(makeShared(id, resource->client(), attrs)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::mesaDRM->m_vBuffers.pop_back(); return; @@ -140,7 +140,7 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co void CMesaDRMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/OutputManagement.cpp b/src/protocols/OutputManagement.cpp index 4a976021..ecca0c48 100644 --- a/src/protocols/OutputManagement.cpp +++ b/src/protocols/OutputManagement.cpp @@ -8,7 +8,7 @@ using namespace Aquamarine; COutputManager::COutputManager(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; LOGM(LOG, "New OutputManager registered"); @@ -23,7 +23,7 @@ COutputManager::COutputManager(SP resource_) : resource(re const auto RESOURCE = PROTO::outputManagement->m_vConfigurations.emplace_back( makeShared(makeShared(resource->client(), resource->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::outputManagement->m_vConfigurations.pop_back(); return; @@ -48,13 +48,13 @@ bool COutputManager::good() { } void COutputManager::makeAndSendNewHead(PHLMONITOR pMonitor) { - if (stopped) + if UNLIKELY (stopped) return; const auto RESOURCE = PROTO::outputManagement->m_vHeads.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), pMonitor)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::outputManagement->m_vHeads.pop_back(); return; @@ -90,7 +90,7 @@ void COutputManager::sendDone() { } COutputHead::COutputHead(SP resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CZwlrOutputHeadV1* r) { PROTO::outputManagement->destroyResource(this); }); @@ -213,7 +213,7 @@ void COutputHead::updateMode() { void COutputHead::makeAndSendNewMode(SP mode) { const auto RESOURCE = PROTO::outputManagement->m_vModes.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), mode)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::outputManagement->m_vModes.pop_back(); return; @@ -229,7 +229,7 @@ PHLMONITOR COutputHead::monitor() { } COutputMode::COutputMode(SP resource_, SP mode_) : resource(resource_), mode(mode_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CZwlrOutputModeV1* r) { PROTO::outputManagement->destroyResource(this); }); @@ -258,7 +258,7 @@ SP COutputMode::getMode() { } COutputConfiguration::COutputConfiguration(SP resource_, SP owner_) : resource(resource_), owner(owner_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwlrOutputConfigurationV1* r) { PROTO::outputManagement->destroyResource(this); }); @@ -282,7 +282,7 @@ COutputConfiguration::COutputConfiguration(SP resour const auto RESOURCE = PROTO::outputManagement->m_vConfigurationHeads.emplace_back( makeShared(makeShared(resource->client(), resource->version(), id), PMONITOR)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::outputManagement->m_vConfigurationHeads.pop_back(); return; @@ -428,7 +428,7 @@ bool COutputConfiguration::applyTestConfiguration(bool test) { } COutputConfigurationHead::COutputConfigurationHead(SP resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwlrOutputConfigurationHeadV1* r) { PROTO::outputManagement->destroyResource(this); }); @@ -581,7 +581,7 @@ COutputManagementProtocol::COutputManagementProtocol(const wl_interface* iface, void COutputManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/OutputPower.cpp b/src/protocols/OutputPower.cpp index dd3e8e1a..f97babc2 100644 --- a/src/protocols/OutputPower.cpp +++ b/src/protocols/OutputPower.cpp @@ -3,7 +3,7 @@ #include "../helpers/Monitor.hpp" COutputPower::COutputPower(SP resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CZwlrOutputPowerV1* r) { PROTO::outputPower->destroyOutputPower(this); }); @@ -62,7 +62,7 @@ void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uin const auto OUTPUT = CWLOutputResource::fromResource(output); - if (!OUTPUT) { + if UNLIKELY (!OUTPUT) { pMgr->error(0, "Invalid output resource"); return; } @@ -70,7 +70,7 @@ void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uin const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vOutputPowers.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id), OUTPUT->monitor.lock())).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vOutputPowers.pop_back(); return; diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp index e12fa75f..c0531799 100644 --- a/src/protocols/PointerConstraints.cpp +++ b/src/protocols/PointerConstraints.cpp @@ -10,7 +10,7 @@ CPointerConstraint::CPointerConstraint(SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) : resourceL(resource_), locked(true), lifetime(lifetime_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource_->setOnDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); @@ -49,7 +49,7 @@ CPointerConstraint::CPointerConstraint(SP resource_, SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) : resourceC(resource_), lifetime(lifetime_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource_->setOnDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); }); @@ -185,7 +185,7 @@ bool CPointerConstraint::isLocked() { } Vector2D CPointerConstraint::logicPositionHint() { - if (!pHLSurface) + if UNLIKELY (!pHLSurface) return {}; const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal(); @@ -218,14 +218,14 @@ void CPointerConstraintsProtocol::destroyPointerConstraint(CPointerConstraint* h } void CPointerConstraintsProtocol::onNewConstraint(SP constraint, CZwpPointerConstraintsV1* pMgr) { - if (!constraint->good()) { + if UNLIKELY (!constraint->good()) { LOGM(ERR, "Couldn't create constraint??"); pMgr->noMemory(); m_vConstraints.pop_back(); return; } - if (!constraint->owner()) { + if UNLIKELY (!constraint->owner()) { LOGM(ERR, "New constraint has no CWLSurface owner??"); return; } @@ -234,7 +234,7 @@ void CPointerConstraintsProtocol::onNewConstraint(SP constra const auto DUPES = std::count_if(m_vConstraints.begin(), m_vConstraints.end(), [OWNER](const auto& c) { return c->owner() == OWNER; }); - if (DUPES > 1) { + if UNLIKELY (DUPES > 1) { LOGM(ERR, "Constraint for surface duped"); pMgr->error(ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "Surface already confined"); m_vConstraints.pop_back(); diff --git a/src/protocols/PointerGestures.cpp b/src/protocols/PointerGestures.cpp index 5dfb9d51..4df51b47 100644 --- a/src/protocols/PointerGestures.cpp +++ b/src/protocols/PointerGestures.cpp @@ -4,7 +4,7 @@ #include "core/Compositor.hpp" CPointerGestureSwipe::CPointerGestureSwipe(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setOnDestroy([this](CZwpPointerGestureSwipeV1* p) { PROTO::pointerGestures->onGestureDestroy(this); }); @@ -16,7 +16,7 @@ bool CPointerGestureSwipe::good() { } CPointerGestureHold::CPointerGestureHold(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setOnDestroy([this](CZwpPointerGestureHoldV1* p) { PROTO::pointerGestures->onGestureDestroy(this); }); @@ -28,7 +28,7 @@ bool CPointerGestureHold::good() { } CPointerGesturePinch::CPointerGesturePinch(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setOnDestroy([this](CZwpPointerGesturePinchV1* p) { PROTO::pointerGestures->onGestureDestroy(this); }); @@ -73,7 +73,7 @@ void CPointerGesturesProtocol::onGetPinchGesture(CZwpPointerGesturesV1* pMgr, ui const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vPinches.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); LOGM(ERR, "Couldn't create gesture"); return; @@ -84,7 +84,7 @@ void CPointerGesturesProtocol::onGetSwipeGesture(CZwpPointerGesturesV1* pMgr, ui const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vSwipes.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); LOGM(ERR, "Couldn't create gesture"); return; @@ -95,7 +95,7 @@ void CPointerGesturesProtocol::onGetHoldGesture(CZwpPointerGesturesV1* pMgr, uin const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vHolds.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); LOGM(ERR, "Couldn't create gesture"); return; diff --git a/src/protocols/PresentationTime.cpp b/src/protocols/PresentationTime.cpp index 411036c3..1654041c 100644 --- a/src/protocols/PresentationTime.cpp +++ b/src/protocols/PresentationTime.cpp @@ -27,7 +27,7 @@ void CQueuedPresentationData::discarded() { } CPresentationFeedback::CPresentationFeedback(SP resource_, SP surf) : resource(resource_), surface(surf) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWpPresentationFeedback* pMgr) { @@ -43,8 +43,8 @@ bool CPresentationFeedback::good() { void CPresentationFeedback::sendQueued(SP data, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) { auto client = resource->client(); - if (PROTO::outputs.contains(data->pMonitor->szName)) { - if (auto outputResource = PROTO::outputs.at(data->pMonitor->szName)->outputResourceFrom(client); outputResource) + if LIKELY (PROTO::outputs.contains(data->pMonitor->szName)) { + if LIKELY (auto outputResource = PROTO::outputs.at(data->pMonitor->szName)->outputResourceFrom(client); outputResource) resource->sendSyncOutput(outputResource->getResource()->resource()); } @@ -100,7 +100,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su m_vFeedbacks.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf))) .get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vFeedbacks.pop_back(); return; diff --git a/src/protocols/PrimarySelection.cpp b/src/protocols/PrimarySelection.cpp index ecc4ee71..567bfdd2 100644 --- a/src/protocols/PrimarySelection.cpp +++ b/src/protocols/PrimarySelection.cpp @@ -5,7 +5,7 @@ #include "../config/ConfigValue.hpp" CPrimarySelectionOffer::CPrimarySelectionOffer(SP resource_, SP source_) : source(source_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpPrimarySelectionOfferV1* r) { PROTO::primarySelection->destroyResource(this); }); @@ -35,7 +35,7 @@ bool CPrimarySelectionOffer::good() { } void CPrimarySelectionOffer::sendData() { - if (!source) + if UNLIKELY (!source) return; for (auto const& m : source->mimes()) { @@ -44,7 +44,7 @@ void CPrimarySelectionOffer::sendData() { } CPrimarySelectionSource::CPrimarySelectionSource(SP resource_, SP device_) : device(device_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -105,7 +105,7 @@ void CPrimarySelectionSource::error(uint32_t code, const std::string& msg) { } CPrimarySelectionDevice::CPrimarySelectionDevice(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -159,7 +159,7 @@ void CPrimarySelectionDevice::sendSelection(SP selection } CPrimarySelectionManager::CPrimarySelectionManager(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwpPrimarySelectionDeviceManagerV1* r) { PROTO::primarySelection->destroyResource(this); }); @@ -168,7 +168,7 @@ CPrimarySelectionManager::CPrimarySelectionManager(SPm_vDevices.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::primarySelection->m_vDevices.pop_back(); return; @@ -192,7 +192,7 @@ CPrimarySelectionManager::CPrimarySelectionManager(SPm_vSources.emplace_back( makeShared(makeShared(r->client(), r->version(), id), device.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::primarySelection->m_vSources.pop_back(); return; @@ -220,7 +220,7 @@ CPrimarySelectionProtocol::CPrimarySelectionProtocol(const wl_interface* iface, void CPrimarySelectionProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/RelativePointer.cpp b/src/protocols/RelativePointer.cpp index b7cf75c6..842af894 100644 --- a/src/protocols/RelativePointer.cpp +++ b/src/protocols/RelativePointer.cpp @@ -4,7 +4,7 @@ #include CRelativePointer::CRelativePointer(SP resource_) : resource(resource_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; pClient = resource->client(); @@ -50,7 +50,7 @@ void CRelativePointerProtocol::onGetRelativePointer(CZwpRelativePointerManagerV1 const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vRelativePointers.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vRelativePointers.pop_back(); return; diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index da0a9412..8bdaf8f9 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -19,7 +19,7 @@ CScreencopyFrame::~CScreencopyFrame() { } CScreencopyFrame::CScreencopyFrame(SP resource_, int32_t overlay_cursor, wl_resource* output, CBox box_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; overlayCursor = !!overlay_cursor; @@ -77,21 +77,20 @@ CScreencopyFrame::CScreencopyFrame(SP resource_, int32_t resource->sendBuffer(NFormatUtils::drmToShm(shmFormat), box.width, box.height, shmStride); if (resource->version() >= 3) { - if (dmabufFormat != DRM_FORMAT_INVALID) { + if LIKELY (dmabufFormat != DRM_FORMAT_INVALID) resource->sendLinuxDmabuf(dmabufFormat, box.width, box.height); - } resource->sendBufferDone(); } } void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_) { - if (!good()) { + if UNLIKELY (!good()) { LOGM(ERR, "No frame in copyFrame??"); return; } - if (!g_pCompositor->monitorExists(pMonitor.lock())) { + if UNLIKELY (!g_pCompositor->monitorExists(pMonitor.lock())) { LOGM(ERR, "Client requested sharing of a monitor that is gone"); resource->sendFailed(); PROTO::screencopy->destroyResource(this); @@ -99,7 +98,7 @@ void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_ } const auto PBUFFER = CWLBufferResource::fromResource(buffer_); - if (!PBUFFER) { + if UNLIKELY (!PBUFFER) { LOGM(ERR, "Invalid buffer in {:x}", (uintptr_t)this); resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer"); PROTO::screencopy->destroyResource(this); @@ -108,14 +107,14 @@ void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_ PBUFFER->buffer->lock(); - if (PBUFFER->buffer->size != box.size()) { + if UNLIKELY (PBUFFER->buffer->size != box.size()) { LOGM(ERR, "Invalid dimensions in {:x}", (uintptr_t)this); resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions"); PROTO::screencopy->destroyResource(this); return; } - if (buffer) { + if UNLIKELY (buffer) { LOGM(ERR, "Buffer used in {:x}", (uintptr_t)this); resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_ALREADY_USED, "frame already used"); PROTO::screencopy->destroyResource(this); @@ -308,7 +307,7 @@ CScreencopyClient::~CScreencopyClient() { } CScreencopyClient::CScreencopyClient(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); }); diff --git a/src/protocols/SecurityContext.cpp b/src/protocols/SecurityContext.cpp index 0818907f..e5b3cf2a 100644 --- a/src/protocols/SecurityContext.cpp +++ b/src/protocols/SecurityContext.cpp @@ -49,7 +49,7 @@ void CSecurityContextSandboxedClient::onDestroy() { } CSecurityContext::CSecurityContext(SP resource_, int listenFD_, int closeFD_) : listenFD(listenFD_), closeFD(closeFD_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWpSecurityContextV1* r) { @@ -64,12 +64,12 @@ CSecurityContext::CSecurityContext(SP resource_, int liste LOGM(LOG, "New security_context at 0x{:x}", (uintptr_t)this); resource->setSetSandboxEngine([this](CWpSecurityContextV1* r, const char* engine) { - if (!sandboxEngine.empty()) { + if UNLIKELY (!sandboxEngine.empty()) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox engine already set"); return; } - if (committed) { + if UNLIKELY (committed) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed"); return; } @@ -79,12 +79,12 @@ CSecurityContext::CSecurityContext(SP resource_, int liste }); resource->setSetAppId([this](CWpSecurityContextV1* r, const char* appid) { - if (!appID.empty()) { + if UNLIKELY (!appID.empty()) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox appid already set"); return; } - if (committed) { + if UNLIKELY (committed) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed"); return; } @@ -94,12 +94,12 @@ CSecurityContext::CSecurityContext(SP resource_, int liste }); resource->setSetInstanceId([this](CWpSecurityContextV1* r, const char* instance) { - if (!instanceID.empty()) { + if UNLIKELY (!instanceID.empty()) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox instance already set"); return; } - if (committed) { + if UNLIKELY (committed) { r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed"); return; } @@ -135,7 +135,7 @@ bool CSecurityContext::good() { } void CSecurityContext::onListen(uint32_t mask) { - if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) { + if UNLIKELY (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) { LOGM(ERR, "security_context at 0x{:x} got an error in listen", (uintptr_t)this); PROTO::securityContext->destroyContext(this); return; @@ -145,13 +145,13 @@ void CSecurityContext::onListen(uint32_t mask) { return; int clientFD = accept(listenFD, nullptr, nullptr); - if (clientFD < 0) { + if UNLIKELY (clientFD < 0) { LOGM(ERR, "security_context at 0x{:x} couldn't accept", (uintptr_t)this); return; } auto newClient = CSecurityContextSandboxedClient::create(clientFD); - if (!newClient) { + if UNLIKELY (!newClient) { LOGM(ERR, "security_context at 0x{:x} couldn't create a client", (uintptr_t)this); close(clientFD); return; @@ -170,7 +170,7 @@ void CSecurityContext::onClose(uint32_t mask) { } CSecurityContextManagerResource::CSecurityContextManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWpSecurityContextManagerV1* r) { PROTO::securityContext->destroyResource(this); }); @@ -180,7 +180,7 @@ CSecurityContextManagerResource::CSecurityContextManagerResource(SPm_vContexts.emplace_back(makeShared(makeShared(r->client(), r->version(), id), lfd, cfd)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::securityContext->m_vContexts.pop_back(); return; @@ -199,7 +199,7 @@ CSecurityContextProtocol::CSecurityContextProtocol(const wl_interface* iface, co void CSecurityContextProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/ServerDecorationKDE.cpp b/src/protocols/ServerDecorationKDE.cpp index c7b98a9c..3e33db52 100644 --- a/src/protocols/ServerDecorationKDE.cpp +++ b/src/protocols/ServerDecorationKDE.cpp @@ -2,7 +2,7 @@ #include "core/Compositor.hpp" CServerDecorationKDE::CServerDecorationKDE(SP resource_, SP surf) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](COrgKdeKwinServerDecoration* pMgr) { PROTO::serverDecorationKDE->destroyResource(this); }); @@ -44,7 +44,7 @@ void CServerDecorationKDEProtocol::createDecoration(COrgKdeKwinServerDecorationM m_vDecos.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf))) .get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vDecos.pop_back(); return; diff --git a/src/protocols/SessionLock.cpp b/src/protocols/SessionLock.cpp index c3f19e53..db65ee5f 100644 --- a/src/protocols/SessionLock.cpp +++ b/src/protocols/SessionLock.cpp @@ -8,7 +8,7 @@ CSessionLockSurface::CSessionLockSurface(SP resource_, SP surface_, PHLMONITOR pMonitor_, WP owner_) : resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CExtSessionLockSurfaceV1* r) { @@ -92,7 +92,7 @@ SP CSessionLockSurface::surface() { } CSessionLock::CSessionLock(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CExtSessionLockV1* r) { PROTO::sessionLock->destroyResource(this); }); @@ -170,7 +170,7 @@ void CSessionLockProtocol::onLock(CExtSessionLockManagerV1* pMgr, uint32_t id) { const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vLocks.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vLocks.pop_back(); return; @@ -198,7 +198,7 @@ void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id const auto RESOURCE = m_vLockSurfaces.emplace_back(makeShared(makeShared(lock->client(), lock->version(), id), PSURFACE, PMONITOR, sessionLock)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { lock->noMemory(); m_vLockSurfaces.pop_back(); return; diff --git a/src/protocols/ShortcutsInhibit.cpp b/src/protocols/ShortcutsInhibit.cpp index 308b385d..a0d29f92 100644 --- a/src/protocols/ShortcutsInhibit.cpp +++ b/src/protocols/ShortcutsInhibit.cpp @@ -4,7 +4,7 @@ #include "core/Compositor.hpp" CKeyboardShortcutsInhibitor::CKeyboardShortcutsInhibitor(SP resource_, SP surf) : resource(resource_), pSurface(surf) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CZwpKeyboardShortcutsInhibitorV1* pMgr) { PROTO::shortcutsInhibit->destroyInhibitor(this); }); @@ -49,7 +49,7 @@ void CKeyboardShortcutsInhibitProtocol::onInhibit(CZwpKeyboardShortcutsInhibitMa const auto CLIENT = pMgr->client(); for (auto const& in : m_vInhibitors) { - if (in->surface() != surf) + if LIKELY (in->surface() != surf) continue; pMgr->error(ZWP_KEYBOARD_SHORTCUTS_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED, "Already inhibited for surface resource"); @@ -59,7 +59,7 @@ void CKeyboardShortcutsInhibitProtocol::onInhibit(CZwpKeyboardShortcutsInhibitMa const auto RESOURCE = m_vInhibitors.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id), surf)).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vInhibitors.pop_back(); LOGM(ERR, "Failed to create an inhibitor resource"); diff --git a/src/protocols/SinglePixel.cpp b/src/protocols/SinglePixel.cpp index 91154671..2fbfc93d 100644 --- a/src/protocols/SinglePixel.cpp +++ b/src/protocols/SinglePixel.cpp @@ -63,7 +63,7 @@ bool CSinglePixelBuffer::good() { CSinglePixelBufferResource::CSinglePixelBufferResource(uint32_t id, wl_client* client, CHyprColor color) { buffer = makeShared(id, client, color); - if (!buffer->good()) + if UNLIKELY (!buffer->good()) return; buffer->resource->buffer = buffer; @@ -83,7 +83,7 @@ bool CSinglePixelBufferResource::good() { } CSinglePixelBufferManagerResource::CSinglePixelBufferManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWpSinglePixelBufferManagerV1* r) { PROTO::singlePixel->destroyResource(this); }); @@ -94,7 +94,7 @@ CSinglePixelBufferManagerResource::CSinglePixelBufferManagerResource(SP::max()}; const auto RESOURCE = PROTO::singlePixel->m_vBuffers.emplace_back(makeShared(id, resource->client(), color)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { res->noMemory(); PROTO::singlePixel->m_vBuffers.pop_back(); return; @@ -113,7 +113,7 @@ CSinglePixelProtocol::CSinglePixelProtocol(const wl_interface* iface, const int& void CSinglePixelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/Tablet.cpp b/src/protocols/Tablet.cpp index 2fdd8731..62e8b2d2 100644 --- a/src/protocols/Tablet.cpp +++ b/src/protocols/Tablet.cpp @@ -9,7 +9,7 @@ #include CTabletPadStripV2Resource::CTabletPadStripV2Resource(SP resource_, uint32_t id_) : id(id_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletPadStripV2* r) { PROTO::tablet->destroyResource(this); }); @@ -21,7 +21,7 @@ bool CTabletPadStripV2Resource::good() { } CTabletPadRingV2Resource::CTabletPadRingV2Resource(SP resource_, uint32_t id_) : id(id_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletPadRingV2* r) { PROTO::tablet->destroyResource(this); }); @@ -33,7 +33,7 @@ bool CTabletPadRingV2Resource::good() { } CTabletPadGroupV2Resource::CTabletPadGroupV2Resource(SP resource_, size_t idx_) : idx(idx_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletPadGroupV2* r) { PROTO::tablet->destroyResource(this); }); @@ -58,7 +58,7 @@ void CTabletPadGroupV2Resource::sendData(SP pad, SPm_vStrips.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), i)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vStrips.pop_back(); return; @@ -71,7 +71,7 @@ void CTabletPadGroupV2Resource::sendData(SP pad, SPm_vRings.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), i)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vRings.pop_back(); return; @@ -84,7 +84,7 @@ void CTabletPadGroupV2Resource::sendData(SP pad, SP resource_, SP pad_, SP seat_) : pad(pad_), seat(seat_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletPadV2* r) { PROTO::tablet->destroyResource(this); }); @@ -114,7 +114,7 @@ void CTabletPadV2Resource::createGroup(SPm_vGroups.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), idx)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vGroups.pop_back(); return; @@ -126,7 +126,7 @@ void CTabletPadV2Resource::createGroup(SP resource_, SP tablet_, SP seat_) : tablet(tablet_), seat(seat_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletV2* r) { PROTO::tablet->destroyResource(this); }); @@ -149,7 +149,7 @@ void CTabletV2Resource::sendData() { } CTabletToolV2Resource::CTabletToolV2Resource(SP resource_, SP tool_, SP seat_) : tool(tool_), seat(seat_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletToolV2* r) { PROTO::tablet->destroyResource(this); }); @@ -228,7 +228,7 @@ void CTabletToolV2Resource::sendFrame(bool removeSource) { } CTabletSeat::CTabletSeat(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpTabletSeatV2* r) { PROTO::tablet->destroyResource(this); }); @@ -243,7 +243,7 @@ void CTabletSeat::sendTool(SP tool) { const auto RESOURCE = PROTO::tablet->m_vTools.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), tool, self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vTools.pop_back(); return; @@ -259,7 +259,7 @@ void CTabletSeat::sendPad(SP pad) { const auto RESOURCE = PROTO::tablet->m_vPads.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), pad, self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vPads.pop_back(); return; @@ -275,7 +275,7 @@ void CTabletSeat::sendTablet(SP tablet) { const auto RESOURCE = PROTO::tablet->m_vTablets.emplace_back(makeShared(makeShared(resource->client(), resource->version(), 0), tablet, self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { resource->noMemory(); PROTO::tablet->m_vTablets.pop_back(); return; @@ -357,7 +357,7 @@ void CTabletV2Protocol::destroyResource(CTabletPadStripV2Resource* resource) { void CTabletV2Protocol::onGetSeat(CZwpTabletManagerV2* pMgr, uint32_t id, wl_resource* seat) { const auto RESOURCE = m_vSeats.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vSeats.pop_back(); return; diff --git a/src/protocols/TearingControl.cpp b/src/protocols/TearingControl.cpp index eb1a53cb..14c80052 100644 --- a/src/protocols/TearingControl.cpp +++ b/src/protocols/TearingControl.cpp @@ -27,7 +27,7 @@ void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) { void CTearingControlProtocol::onGetController(wl_client* client, CWpTearingControlManagerV1* pMgr, uint32_t id, SP surf) { const auto CONTROLLER = m_vTearingControllers.emplace_back(std::make_unique(makeShared(client, pMgr->version(), id), surf)).get(); - if (!CONTROLLER->good()) { + if UNLIKELY (!CONTROLLER->good()) { pMgr->noMemory(); m_vTearingControllers.pop_back(); return; @@ -67,7 +67,7 @@ void CTearingControl::onHint(wpTearingControlV1PresentationHint hint_) { } void CTearingControl::updateWindow() { - if (pWindow.expired()) + if UNLIKELY (pWindow.expired()) return; pWindow->m_bTearingHint = hint == WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC; diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp index b8eb5835..4bf5e9e1 100644 --- a/src/protocols/TextInputV1.cpp +++ b/src/protocols/TextInputV1.cpp @@ -7,13 +7,13 @@ CTextInputV1::~CTextInputV1() { } CTextInputV1::CTextInputV1(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CZwpTextInputV1* pMgr) { PROTO::textInputV1->destroyResource(this); }); resource->setActivate([this](CZwpTextInputV1* pMgr, wl_resource* seat, wl_resource* surface) { - if (!surface) { + if UNLIKELY (!surface) { LOGM(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)this); return; } @@ -105,7 +105,7 @@ void CTextInputV1Protocol::bindManager(wl_client* client, void* data, uint32_t v const auto PTI = m_vClients.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id))); LOGM(LOG, "New TI V1 at {:x}", (uintptr_t)PTI.get()); - if (!PTI->good()) { + if UNLIKELY (!PTI->good()) { LOGM(ERR, "Could not alloc wl_resource for TIV1"); pMgr->noMemory(); PROTO::textInputV1->destroyResource(PTI.get()); diff --git a/src/protocols/TextInputV3.cpp b/src/protocols/TextInputV3.cpp index 30374104..71ef6dac 100644 --- a/src/protocols/TextInputV3.cpp +++ b/src/protocols/TextInputV3.cpp @@ -10,7 +10,7 @@ void CTextInputV3::SState::reset() { } CTextInputV3::CTextInputV3(SP resource_) : resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; LOGM(LOG, "New tiv3 at {:016x}", (uintptr_t)this); @@ -129,7 +129,7 @@ void CTextInputV3Protocol::onGetTextInput(CZwpTextInputManagerV3* pMgr, uint32_t const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vTextInputs.emplace_back(makeShared(makeShared(CLIENT, pMgr->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vTextInputs.pop_back(); LOGM(ERR, "Failed to create a tiv3 resource"); diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index 8e34cf4b..2d40cb78 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -13,7 +13,7 @@ #include CToplevelExportClient::CToplevelExportClient(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CHyprlandToplevelExportManagerV1* pMgr) { PROTO::toplevelExport->destroyResource(this); }); @@ -35,7 +35,7 @@ void CToplevelExportClient::captureToplevel(CHyprlandToplevelExportManagerV1* pM const auto FRAME = PROTO::toplevelExport->m_vFrames.emplace_back( makeShared(makeShared(resource->client(), resource->version(), frame), overlayCursor_, handle)); - if (!FRAME->good()) { + if UNLIKELY (!FRAME->good()) { LOGM(ERR, "Couldn't alloc frame for sharing! (no memory)"); resource->noMemory(); PROTO::toplevelExport->destroyResource(FRAME.get()); @@ -78,19 +78,19 @@ CToplevelExportFrame::~CToplevelExportFrame() { } CToplevelExportFrame::CToplevelExportFrame(SP resource_, int32_t overlayCursor_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) { - if (!good()) + if UNLIKELY (!good()) return; cursorOverlayRequested = !!overlayCursor_; - if (!pWindow) { + if UNLIKELY (!pWindow) { LOGM(ERR, "Client requested sharing of window handle {:x} which does not exist!", pWindow); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); return; } - if (!pWindow->m_bIsMapped) { + if UNLIKELY (!pWindow->m_bIsMapped) { LOGM(ERR, "Client requested sharing of window handle {:x} which is not shareable!", pWindow); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); @@ -106,7 +106,7 @@ CToplevelExportFrame::CToplevelExportFrame(SP re g_pHyprRenderer->makeEGLCurrent(); shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PMONITOR); - if (shmFormat == DRM_FORMAT_INVALID) { + if UNLIKELY (shmFormat == DRM_FORMAT_INVALID) { LOGM(ERR, "No format supported by renderer in capture toplevel"); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); @@ -114,7 +114,7 @@ CToplevelExportFrame::CToplevelExportFrame(SP re } const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(shmFormat); - if (!PSHMINFO) { + if UNLIKELY (!PSHMINFO) { LOGM(ERR, "No pixel format supported by renderer in capture toplevel"); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); @@ -131,27 +131,26 @@ CToplevelExportFrame::CToplevelExportFrame(SP re resource->sendBuffer(NFormatUtils::drmToShm(shmFormat), box.width, box.height, shmStride); - if (dmabufFormat != DRM_FORMAT_INVALID) { + if LIKELY (dmabufFormat != DRM_FORMAT_INVALID) resource->sendLinuxDmabuf(dmabufFormat, box.width, box.height); - } resource->sendBufferDone(); } void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resource* buffer_, int32_t ignoreDamage) { - if (!good()) { + if UNLIKELY (!good()) { LOGM(ERR, "No frame in copyFrame??"); return; } - if (!validMapped(pWindow)) { + if UNLIKELY (!validMapped(pWindow)) { LOGM(ERR, "Client requested sharing of window handle {:x} which is gone!", pWindow); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); return; } - if (!pWindow->m_bIsMapped) { + if UNLIKELY (!pWindow->m_bIsMapped) { LOGM(ERR, "Client requested sharing of window handle {:x} which is not shareable (2)!", pWindow); resource->sendFailed(); PROTO::toplevelExport->destroyResource(this); @@ -159,7 +158,7 @@ void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resou } const auto PBUFFER = CWLBufferResource::fromResource(buffer_); - if (!PBUFFER) { + if UNLIKELY (!PBUFFER) { resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer"); PROTO::toplevelExport->destroyResource(this); return; @@ -167,13 +166,13 @@ void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resou PBUFFER->buffer->lock(); - if (PBUFFER->buffer->size != box.size()) { + if UNLIKELY (PBUFFER->buffer->size != box.size()) { resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions"); PROTO::toplevelExport->destroyResource(this); return; } - if (buffer) { + if UNLIKELY (buffer) { resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_ALREADY_USED, "frame already used"); PROTO::toplevelExport->destroyResource(this); return; diff --git a/src/protocols/Viewporter.cpp b/src/protocols/Viewporter.cpp index 58cb851d..4964bead 100644 --- a/src/protocols/Viewporter.cpp +++ b/src/protocols/Viewporter.cpp @@ -3,14 +3,14 @@ #include CViewportResource::CViewportResource(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWpViewport* r) { PROTO::viewport->destroyResource(this); }); resource->setOnDestroy([this](CWpViewport* r) { PROTO::viewport->destroyResource(this); }); resource->setSetDestination([this](CWpViewport* r, int32_t x, int32_t y) { - if (!surface) { + if UNLIKELY (!surface) { r->error(WP_VIEWPORT_ERROR_NO_SURFACE, "Surface is gone"); return; } @@ -20,7 +20,7 @@ CViewportResource::CViewportResource(SP resource_, SPerror(WP_VIEWPORT_ERROR_BAD_SIZE, "Size was <= 0"); return; } @@ -30,7 +30,7 @@ CViewportResource::CViewportResource(SP resource_, SPsetSetSource([this](CWpViewport* r, wl_fixed_t fx, wl_fixed_t fy, wl_fixed_t fw, wl_fixed_t fh) { - if (!surface) { + if UNLIKELY (!surface) { r->error(WP_VIEWPORT_ERROR_NO_SURFACE, "Surface is gone"); return; } @@ -42,7 +42,7 @@ CViewportResource::CViewportResource(SP resource_, SPerror(WP_VIEWPORT_ERROR_BAD_SIZE, "Pos was < 0"); return; } @@ -80,7 +80,7 @@ bool CViewportResource::good() { } CViewporterResource::CViewporterResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWpViewporter* r) { PROTO::viewport->destroyResource(this); }); @@ -90,7 +90,7 @@ CViewporterResource::CViewporterResource(SP resource_) : resource const auto RESOURCE = PROTO::viewport->m_vViewports.emplace_back( makeShared(makeShared(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::viewport->m_vViewports.pop_back(); return; @@ -109,7 +109,7 @@ CViewporterProtocol::CViewporterProtocol(const wl_interface* iface, const int& v void CViewporterProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/VirtualKeyboard.cpp b/src/protocols/VirtualKeyboard.cpp index bb51315d..7da1fe01 100644 --- a/src/protocols/VirtualKeyboard.cpp +++ b/src/protocols/VirtualKeyboard.cpp @@ -3,7 +3,7 @@ #include "../devices/IKeyboard.hpp" CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwpVirtualKeyboardV1* r) { @@ -18,7 +18,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP }); resource->setKey([this](CZwpVirtualKeyboardV1* r, uint32_t timeMs, uint32_t key, uint32_t state) { - if (!hasKeymap) { + if UNLIKELY (!hasKeymap) { r->error(ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP, "Key event received before a keymap was set"); return; } @@ -37,7 +37,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP }); resource->setModifiers([this](CZwpVirtualKeyboardV1* r, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) { - if (!hasKeymap) { + if UNLIKELY (!hasKeymap) { r->error(ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP, "Mods event received before a keymap was set"); return; } @@ -52,7 +52,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP resource->setKeymap([this](CZwpVirtualKeyboardV1* r, uint32_t fmt, int32_t fd, uint32_t len) { auto xkbContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - if (!xkbContext) { + if UNLIKELY (!xkbContext) { LOGM(ERR, "xkbContext creation failed"); r->noMemory(); close(fd); @@ -60,7 +60,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP } auto keymapData = mmap(nullptr, len, PROT_READ, MAP_PRIVATE, fd, 0); - if (keymapData == MAP_FAILED) { + if UNLIKELY (keymapData == MAP_FAILED) { LOGM(ERR, "keymapData alloc failed"); xkb_context_unref(xkbContext); r->noMemory(); @@ -71,7 +71,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP auto xkbKeymap = xkb_keymap_new_from_string(xkbContext, (const char*)keymapData, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(keymapData, len); - if (!xkbKeymap) { + if UNLIKELY (!xkbKeymap) { LOGM(ERR, "xkbKeymap creation failed"); xkb_context_unref(xkbContext); r->noMemory(); @@ -142,7 +142,7 @@ void CVirtualKeyboardProtocol::onCreateKeeb(CZwpVirtualKeyboardManagerV1* pMgr, const auto RESOURCE = m_vKeyboards.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vKeyboards.pop_back(); return; diff --git a/src/protocols/VirtualPointer.cpp b/src/protocols/VirtualPointer.cpp index 4c5aa13a..3e0b00eb 100644 --- a/src/protocols/VirtualPointer.cpp +++ b/src/protocols/VirtualPointer.cpp @@ -2,7 +2,7 @@ #include "core/Output.hpp" CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP resource_, PHLMONITORREF boundOutput_) : boundOutput(boundOutput_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CZwlrVirtualPointerV1* r) { @@ -41,7 +41,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP r }); resource->setAxis([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_, wl_fixed_t value) { - if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { + if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis"); return; } @@ -64,7 +64,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP r resource->setAxisSource([this](CZwlrVirtualPointerV1* r, uint32_t source) { axisEvents[axis].source = (wl_pointer_axis_source)source; }); resource->setAxisStop([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_) { - if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { + if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis"); return; } @@ -77,7 +77,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP r }); resource->setAxisDiscrete([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_, wl_fixed_t value, int32_t discrete) { - if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { + if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) { r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis"); return; } @@ -138,7 +138,7 @@ void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr const auto RESOURCE = m_vPointers.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id), output)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vPointers.pop_back(); return; diff --git a/src/protocols/WaylandProtocol.cpp b/src/protocols/WaylandProtocol.cpp index 5c6a4a56..7fef5179 100644 --- a/src/protocols/WaylandProtocol.cpp +++ b/src/protocols/WaylandProtocol.cpp @@ -20,7 +20,7 @@ void IWaylandProtocol::onDisplayDestroy() { IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name) : m_szName(name), m_pGlobal(wl_global_create(g_pCompositor->m_sWLDisplay, iface, ver, this, &bindManagerInternal)) { - if (!m_pGlobal) { + if UNLIKELY (!m_pGlobal) { LOGM(ERR, "could not create a global [{}]", m_szName); return; } diff --git a/src/protocols/XDGActivation.cpp b/src/protocols/XDGActivation.cpp index 4a6c7bfe..c49dc3dc 100644 --- a/src/protocols/XDGActivation.cpp +++ b/src/protocols/XDGActivation.cpp @@ -5,7 +5,7 @@ #include CXDGActivationToken::CXDGActivationToken(SP resource_) : resource(resource_) { - if (!resource_->resource()) + if UNLIKELY (!resource_->resource()) return; resource->setDestroy([this](CXdgActivationTokenV1* r) { PROTO::activation->destroyToken(this); }); @@ -18,7 +18,7 @@ CXDGActivationToken::CXDGActivationToken(SP resource_) : resource->setCommit([this](CXdgActivationTokenV1* r) { // TODO: should we send a protocol error of already_used here // if it was used? the protocol spec doesn't say _when_ it should be sent... - if (committed) { + if UNLIKELY (committed) { LOGM(WARN, "possible protocol error, two commits from one token. Ignoring."); return; } @@ -36,7 +36,7 @@ CXDGActivationToken::CXDGActivationToken(SP resource_) : auto count = std::count_if(PROTO::activation->m_vSentTokens.begin(), PROTO::activation->m_vSentTokens.end(), [this](const auto& other) { return other.client == resource->client(); }); - if (count > 10) { + if UNLIKELY (count > 10) { // remove first token. Too many, dear app. for (auto i = PROTO::activation->m_vSentTokens.begin(); i != PROTO::activation->m_vSentTokens.end(); ++i) { if (i->client == resource->client()) { @@ -70,7 +70,7 @@ void CXDGActivationProtocol::bindManager(wl_client* client, void* data, uint32_t RESOURCE->setActivate([this](CXdgActivationV1* pMgr, const char* token, wl_resource* surface) { auto TOKEN = std::find_if(m_vSentTokens.begin(), m_vSentTokens.end(), [token](const auto& t) { return t.token == token; }); - if (TOKEN == m_vSentTokens.end()) { + if UNLIKELY (TOKEN == m_vSentTokens.end()) { LOGM(WARN, "activate event for non-existent token {}??", token); return; } @@ -81,7 +81,7 @@ void CXDGActivationProtocol::bindManager(wl_client* client, void* data, uint32_t SP surf = CWLSurfaceResource::fromResource(surface); const auto PWINDOW = g_pCompositor->getWindowFromSurface(surf); - if (!PWINDOW) { + if UNLIKELY (!PWINDOW) { LOGM(WARN, "activate event for non-window or gone surface with token {}, ignoring", token); return; } @@ -102,7 +102,7 @@ void CXDGActivationProtocol::onGetToken(CXdgActivationV1* pMgr, uint32_t id) { const auto CLIENT = pMgr->client(); const auto RESOURCE = m_vTokens.emplace_back(std::make_unique(makeShared(CLIENT, pMgr->version(), id))).get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_vTokens.pop_back(); return; diff --git a/src/protocols/XDGDecoration.cpp b/src/protocols/XDGDecoration.cpp index 07b1694c..8ec0d5b0 100644 --- a/src/protocols/XDGDecoration.cpp +++ b/src/protocols/XDGDecoration.cpp @@ -2,7 +2,7 @@ #include CXDGDecoration::CXDGDecoration(SP resource_, wl_resource* toplevel) : resource(resource_), pToplevelResource(toplevel) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([this](CZxdgToplevelDecorationV1* pMgr) { PROTO::xdgDecoration->destroyDecoration(this); }); @@ -57,7 +57,7 @@ void CXDGDecorationProtocol::destroyDecoration(CXDGDecoration* decoration) { } void CXDGDecorationProtocol::onGetDecoration(CZxdgDecorationManagerV1* pMgr, uint32_t id, wl_resource* xdgToplevel) { - if (m_mDecorations.contains(xdgToplevel)) { + if UNLIKELY (m_mDecorations.contains(xdgToplevel)) { pMgr->error(ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ALREADY_CONSTRUCTED, "Decoration object already exists"); return; } @@ -66,7 +66,7 @@ void CXDGDecorationProtocol::onGetDecoration(CZxdgDecorationManagerV1* pMgr, uin const auto RESOURCE = m_mDecorations.emplace(xdgToplevel, std::make_unique(makeShared(CLIENT, pMgr->version(), id), xdgToplevel)).first->second.get(); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { pMgr->noMemory(); m_mDecorations.erase(xdgToplevel); return; diff --git a/src/protocols/XDGDialog.cpp b/src/protocols/XDGDialog.cpp index 3f58f326..675d4e78 100644 --- a/src/protocols/XDGDialog.cpp +++ b/src/protocols/XDGDialog.cpp @@ -5,7 +5,7 @@ #include CXDGDialogV1Resource::CXDGDialogV1Resource(SP resource_, SP toplevel_) : resource(resource_), toplevel(toplevel_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXdgDialogV1* r) { PROTO::xdgDialog->destroyResource(this); }); @@ -23,11 +23,11 @@ CXDGDialogV1Resource::CXDGDialogV1Resource(SP resource_, SPparent || !toplevel->parent->owner) + if UNLIKELY (!toplevel || !toplevel->parent || !toplevel->parent->owner) return; auto HLSurface = CWLSurface::fromResource(toplevel->parent->owner->surface.lock()); - if (!HLSurface || !HLSurface->getWindow()) + if UNLIKELY (!HLSurface || !HLSurface->getWindow()) return; g_pCompositor->updateWindowAnimatedDecorationValues(HLSurface->getWindow()); @@ -38,7 +38,7 @@ bool CXDGDialogV1Resource::good() { } CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXdgWmDialogV1* r) { PROTO::xdgDialog->destroyResource(this); }); @@ -46,14 +46,14 @@ CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP reso resource->setGetXdgDialog([](CXdgWmDialogV1* r, uint32_t id, wl_resource* toplevel) { auto tl = CXDGToplevelResource::fromResource(toplevel); - if (!tl) { + if UNLIKELY (!tl) { r->error(-1, "Toplevel inert"); return; } const auto RESOURCE = PROTO::xdgDialog->m_vDialogs.emplace_back(makeShared(makeShared(r->client(), r->version(), id), tl)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); return; } @@ -73,7 +73,7 @@ CXDGDialogProtocol::CXDGDialogProtocol(const wl_interface* iface, const int& ver void CXDGDialogProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); return; } diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index fadc48a1..5be16d07 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -23,7 +23,7 @@ void CXDGOutputProtocol::onOutputResourceDestroy(wl_resource* res) { void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique(client, ver, id)).get(); - if (!RESOURCE->resource()) { + if UNLIKELY (!RESOURCE->resource()) { LOGM(LOG, "Couldn't bind XDGOutputMgr"); wl_client_post_no_memory(client); return; @@ -53,13 +53,13 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32 pXDGOutput->outputProto = OUTPUT->owner; - if (!pXDGOutput->resource->resource()) { + if UNLIKELY (!pXDGOutput->resource->resource()) { m_vXDGOutputs.pop_back(); mgr->noMemory(); return; } - if (!PMONITOR) { + if UNLIKELY (!PMONITOR) { LOGM(ERR, "New xdg_output from client {:x} ({}) has no CMonitor?!", (uintptr_t)CLIENT, pXDGOutput->isXWayland ? "xwayland" : "not xwayland"); return; } @@ -96,7 +96,7 @@ void CXDGOutputProtocol::updateAllOutputs() { // CXDGOutput::CXDGOutput(SP resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) { - if (!resource->resource()) + if UNLIKELY (!resource->resource()) return; resource->setDestroy([](CZxdgOutputV1* pMgr) { PROTO::xdgOutput->onOutputResourceDestroy(pMgr->resource()); }); @@ -106,7 +106,7 @@ CXDGOutput::CXDGOutput(SP resource_, PHLMONITOR monitor_) : monit void CXDGOutput::sendDetails() { static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - if (!monitor || !outputProto || outputProto->isDefunct()) + if UNLIKELY (!monitor || !outputProto || outputProto->isDefunct()) return; const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition; diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index aabb225a..f5d1a8fa 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -26,7 +26,7 @@ void SXDGPositionerState::setGravity(xdgPositionerGravity edges) { CXDGPopupResource::CXDGPopupResource(SP resource_, SP owner_, SP surface_, SP positioner) : surface(surface_), parent(owner_), resource(resource_), positionerRules(positioner) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -79,7 +79,7 @@ void CXDGPopupResource::applyPositioning(const CBox& box, const Vector2D& t1coor configure(geometry); - if (lastRepositionToken) + if UNLIKELY (lastRepositionToken) repositioned(); } @@ -118,7 +118,7 @@ void CXDGPopupResource::done() { } void CXDGPopupResource::repositioned() { - if (!lastRepositionToken) + if LIKELY (!lastRepositionToken) return; LOGM(LOG, "repositioned: sending reposition token {}", lastRepositionToken); @@ -128,7 +128,7 @@ void CXDGPopupResource::repositioned() { } CXDGToplevelResource::CXDGToplevelResource(SP resource_, SP owner_) : owner(owner_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -350,7 +350,7 @@ Vector2D CXDGToplevelResource::layoutMaxSize() { CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SP owner_, SP surface_) : owner(owner_), surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -386,7 +386,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPcurrent = toplevel->pending; - if (initialCommit && surface->pending.texture) { + if UNLIKELY (initialCommit && surface->pending.texture) { resource->error(-1, "Buffer attached before initial commit"); return; } @@ -416,7 +416,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPsetGetToplevel([this](CXdgSurface* r, uint32_t id) { const auto RESOURCE = PROTO::xdgShell->m_vToplevels.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::xdgShell->m_vToplevels.pop_back(); return; @@ -442,7 +442,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP resource_, SPm_vPopups.emplace_back(makeShared(makeShared(r->client(), r->version(), id), parent, self.lock(), positioner)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::xdgShell->m_vPopups.pop_back(); return; @@ -511,7 +511,7 @@ void CXDGSurfaceResource::configure() { } CXDGPositionerResource::CXDGPositionerResource(SP resource_, SP owner_) : owner(owner_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -520,7 +520,7 @@ CXDGPositionerResource::CXDGPositionerResource(SP resource_, SP< resource->setOnDestroy([this](CXdgPositioner* r) { PROTO::xdgShell->destroyResource(this); }); resource->setSetSize([this](CXdgPositioner* r, int32_t x, int32_t y) { - if (x <= 0 || y <= 0) { + if UNLIKELY (x <= 0 || y <= 0) { r->error(XDG_POSITIONER_ERROR_INVALID_INPUT, "Invalid size"); return; } @@ -529,7 +529,7 @@ CXDGPositionerResource::CXDGPositionerResource(SP resource_, SP< }); resource->setSetAnchorRect([this](CXdgPositioner* r, int32_t x, int32_t y, int32_t w, int32_t h) { - if (w <= 0 || h <= 0) { + if UNLIKELY (w <= 0 || h <= 0) { r->error(XDG_POSITIONER_ERROR_INVALID_INPUT, "Invalid box"); return; } @@ -686,7 +686,7 @@ CBox CXDGPositionerRules::getPosition(CBox constraint, const Vector2D& parentCoo } CXDGWMBase::CXDGWMBase(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXdgWmBase* r) { PROTO::xdgShell->destroyResource(this); }); @@ -698,7 +698,7 @@ CXDGWMBase::CXDGWMBase(SP resource_) : resource(resource_) { const auto RESOURCE = PROTO::xdgShell->m_vPositioners.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::xdgShell->m_vPositioners.pop_back(); return; @@ -714,19 +714,19 @@ CXDGWMBase::CXDGWMBase(SP resource_) : resource(resource_) { resource->setGetXdgSurface([this](CXdgWmBase* r, uint32_t id, wl_resource* surf) { auto SURF = CWLSurfaceResource::fromResource(surf); - if (!SURF) { + if UNLIKELY (!SURF) { r->error(-1, "Invalid surface passed"); return; } - if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { + if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { r->error(-1, "Surface already has a different role"); return; } const auto RESOURCE = PROTO::xdgShell->m_vSurfaces.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock(), SURF)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::xdgShell->m_vSurfaces.pop_back(); return; @@ -765,7 +765,7 @@ CXDGShellProtocol::CXDGShellProtocol(const wl_interface* iface, const int& ver, void CXDGShellProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vWMBases.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vWMBases.pop_back(); return; diff --git a/src/protocols/XWaylandShell.cpp b/src/protocols/XWaylandShell.cpp index 81194163..b4615e19 100644 --- a/src/protocols/XWaylandShell.cpp +++ b/src/protocols/XWaylandShell.cpp @@ -3,7 +3,7 @@ #include CXWaylandSurfaceResource::CXWaylandSurfaceResource(SP resource_, SP surface_) : surface(surface_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXwaylandSurfaceV1* r) { @@ -36,7 +36,7 @@ wl_client* CXWaylandSurfaceResource::client() { } CXWaylandShellResource::CXWaylandShellResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXwaylandShellV1* r) { PROTO::xwaylandShell->destroyResource(this); }); @@ -46,7 +46,7 @@ CXWaylandShellResource::CXWaylandShellResource(SP resource_) : const auto RESOURCE = PROTO::xwaylandShell->m_vSurfaces.emplace_back( makeShared(makeShared(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surface))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::xwaylandShell->m_vSurfaces.pop_back(); return; @@ -67,7 +67,7 @@ CXWaylandShellProtocol::CXWaylandShellProtocol(const wl_interface* iface, const void CXWaylandShellProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index e1d6ef7d..93683993 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -34,7 +34,7 @@ void CWLCallbackResource::send(timespec* now) { } CWLRegionResource::CWLRegionResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -56,7 +56,7 @@ SP CWLRegionResource::fromResource(wl_resource* res) { } CWLSurfaceResource::CWLSurfaceResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; pClient = resource->client(); @@ -187,20 +187,20 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) { if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end()) return; - if (!PROTO::outputs.contains(monitor->szName)) { + if UNLIKELY (!PROTO::outputs.contains(monitor->szName)) { // can happen on unplug/replug LOGM(ERR, "enter() called on a non-existent output global"); return; } - if (PROTO::outputs.at(monitor->szName)->isDefunct()) { + if UNLIKELY (PROTO::outputs.at(monitor->szName)->isDefunct()) { LOGM(ERR, "enter() called on a defunct output global"); return; } auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient); - if (!output || !output->getResource() || !output->getResource()->resource()) { + if UNLIKELY (!output || !output->getResource() || !output->getResource()->resource()) { LOGM(ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->szName); return; } @@ -211,12 +211,12 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) { } void CWLSurfaceResource::leave(PHLMONITOR monitor) { - if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end()) + if UNLIKELY (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end()) return; auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient); - if (!output) { + if UNLIKELY (!output) { LOGM(ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->szName); return; } @@ -332,7 +332,7 @@ uint32_t CWLSurfaceResource::id() { } void CWLSurfaceResource::map() { - if (mapped) + if UNLIKELY (mapped) return; mapped = true; @@ -346,7 +346,7 @@ void CWLSurfaceResource::map() { } void CWLSurfaceResource::unmap() { - if (!mapped) + if UNLIKELY (!mapped) return; mapped = false; @@ -385,10 +385,10 @@ CBox CWLSurfaceResource::extends() { } Vector2D CWLSurfaceResource::sourceSize() { - if (!current.texture) + if UNLIKELY (!current.texture) return {}; - if (current.viewport.hasSource) + if UNLIKELY (current.viewport.hasSource) return current.viewport.source.size(); Vector2D trc = current.transform % 2 == 1 ? Vector2D{current.bufferSize.y, current.bufferSize.x} : current.bufferSize; @@ -396,7 +396,7 @@ Vector2D CWLSurfaceResource::sourceSize() { } CRegion CWLSurfaceResource::accumulateCurrentBufferDamage() { - if (!current.texture) + if UNLIKELY (!current.texture) return {}; CRegion surfaceDamage = current.damage; @@ -495,7 +495,7 @@ void CWLSurfaceResource::commitPendingState() { void CWLSurfaceResource::updateCursorShm(CRegion damage) { auto buf = current.buffer ? current.buffer->buffer : lastBuffer; - if (!buf) + if UNLIKELY (!buf) return; auto& shmData = CCursorSurfaceRole::cursorPixelData(self.lock()); @@ -545,7 +545,7 @@ void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor, bo } CWLCompositorResource::CWLCompositorResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlCompositor* r) { PROTO::compositor->destroyResource(this); }); @@ -553,7 +553,7 @@ CWLCompositorResource::CWLCompositorResource(SP resource_) : reso resource->setCreateSurface([](CWlCompositor* r, uint32_t id) { const auto RESOURCE = PROTO::compositor->m_vSurfaces.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::compositor->m_vSurfaces.pop_back(); return; @@ -569,7 +569,7 @@ CWLCompositorResource::CWLCompositorResource(SP resource_) : reso resource->setCreateRegion([](CWlCompositor* r, uint32_t id) { const auto RESOURCE = PROTO::compositor->m_vRegions.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::compositor->m_vRegions.pop_back(); return; @@ -592,7 +592,7 @@ CWLCompositorProtocol::CWLCompositorProtocol(const wl_interface* iface, const in void CWLCompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index fd3cd1fa..ade16498 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -15,7 +15,7 @@ #include "../../render/Renderer.hpp" CWLDataOfferResource::CWLDataOfferResource(SP resource_, SP source_) : source(source_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); }); @@ -127,7 +127,7 @@ SP CWLDataOfferResource::getSource() { } CWLDataSourceResource::CWLDataSourceResource(SP resource_, SP device_) : device(device_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -237,7 +237,7 @@ eDataSourceType CWLDataSourceResource::type() { } CWLDataDeviceResource::CWLDataDeviceResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); }); @@ -333,7 +333,7 @@ SP CWLDataDeviceResource::getX11() { } CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlDataDeviceManager* r) { PROTO::data->destroyResource(this); }); @@ -343,7 +343,7 @@ CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SPm_vSources.emplace_back(makeShared(makeShared(r->client(), r->version(), id), device.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::data->m_vSources.pop_back(); return; @@ -362,7 +362,7 @@ CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SPsetGetDataDevice([this](CWlDataDeviceManager* r, uint32_t id, wl_resource* seat) { const auto RESOURCE = PROTO::data->m_vDevices.emplace_back(makeShared(makeShared(r->client(), r->version(), id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::data->m_vDevices.pop_back(); return; @@ -394,7 +394,7 @@ CWLDataDeviceProtocol::CWLDataDeviceProtocol(const wl_interface* iface, const in void CWLDataDeviceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; @@ -441,7 +441,7 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP dev, SPgetWayland(); WL) { const auto OFFER = m_vOffers.emplace_back(makeShared(makeShared(WL->resource->client(), WL->resource->version(), 0), sel)); - if (!OFFER->good()) { + if UNLIKELY (!OFFER->good()) { WL->resource->noMemory(); m_vOffers.pop_back(); return; @@ -455,7 +455,7 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP dev, SPpWM->createX11DataOffer(g_pSeatManager->state.keyboardFocus.lock(), sel); #endif - if (!offer) { + if UNLIKELY (!offer) { LOGM(ERR, "No offer could be created in sendSelectionToDevice"); return; } diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index db580457..77f0661e 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -4,7 +4,7 @@ #include "../../helpers/Monitor.hpp" CWLOutputResource::CWLOutputResource(SP resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setData(this); @@ -94,12 +94,12 @@ CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, } void CWLOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { - if (defunct) + if UNLIKELY (defunct) Debug::log(WARN, "[wl_output] Binding a wl_output that's inert?? Possible client bug."); const auto RESOURCE = m_vOutputs.emplace_back(makeShared(makeShared(client, ver, id), monitor.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vOutputs.pop_back(); return; @@ -128,7 +128,7 @@ SP CWLOutputProtocol::outputResourceFrom(wl_client* client) { } void CWLOutputProtocol::remove() { - if (defunct) + if UNLIKELY (defunct) return; defunct = true; @@ -140,7 +140,7 @@ bool CWLOutputProtocol::isDefunct() { } void CWLOutputProtocol::sendDone() { - if (defunct) + if UNLIKELY (defunct) return; for (auto const& r : m_vOutputs) { diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp index f7969a4d..c6b2de05 100644 --- a/src/protocols/core/Seat.cpp +++ b/src/protocols/core/Seat.cpp @@ -10,7 +10,7 @@ #include CWLTouchResource::CWLTouchResource(SP resource_, SP owner_) : owner(owner_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CWlTouch* r) { PROTO::seat->destroyResource(this); }); @@ -105,7 +105,7 @@ void CWLTouchResource::sendOrientation(int32_t id, double angle) { } CWLPointerResource::CWLPointerResource(SP resource_, SP owner_) : owner(owner_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); }); @@ -292,7 +292,7 @@ void CWLPointerResource::sendAxisRelativeDirection(wl_pointer_axis axis, wl_poin } CWLKeyboardResource::CWLKeyboardResource(SP resource_, SP owner_) : owner(owner_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setRelease([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); }); @@ -419,7 +419,7 @@ void CWLKeyboardResource::repeatInfo(uint32_t rate, uint32_t delayMs) { } CWLSeatResource::CWLSeatResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlSeat* r) { @@ -436,7 +436,7 @@ CWLSeatResource::CWLSeatResource(SP resource_) : resource(resource_) { resource->setGetKeyboard([this](CWlSeat* r, uint32_t id) { const auto RESOURCE = PROTO::seat->m_vKeyboards.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::seat->m_vKeyboards.pop_back(); return; @@ -448,7 +448,7 @@ CWLSeatResource::CWLSeatResource(SP resource_) : resource(resource_) { resource->setGetPointer([this](CWlSeat* r, uint32_t id) { const auto RESOURCE = PROTO::seat->m_vPointers.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::seat->m_vPointers.pop_back(); return; @@ -460,7 +460,7 @@ CWLSeatResource::CWLSeatResource(SP resource_) : resource(resource_) { resource->setGetTouch([this](CWlSeat* r, uint32_t id) { const auto RESOURCE = PROTO::seat->m_vTouches.emplace_back(makeShared(makeShared(r->client(), r->version(), id), self.lock())); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::seat->m_vTouches.pop_back(); return; @@ -506,7 +506,7 @@ CWLSeatProtocol::CWLSeatProtocol(const wl_interface* iface, const int& ver, cons void CWLSeatProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vSeatResources.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vSeatResources.pop_back(); return; diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp index 6365c5d6..28585aeb 100644 --- a/src/protocols/core/Shm.cpp +++ b/src/protocols/core/Shm.cpp @@ -9,7 +9,7 @@ #include "../../render/Renderer.hpp" CWLSHMBuffer::CWLSHMBuffer(SP pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) { - if (!pool_->pool->data) + if UNLIKELY (!pool_->pool->data) return; g_pHyprRenderer->makeEGLCurrent(); @@ -32,7 +32,7 @@ CWLSHMBuffer::CWLSHMBuffer(SP pool_, uint32_t id, int32_t of success = texture->m_iTexID; - if (!success) + if UNLIKELY (!success) Debug::log(ERR, "Failed creating a shm texture: null texture id"); } @@ -96,13 +96,13 @@ void CSHMPool::resize(size_t size_) { size = size_; data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) + if UNLIKELY (data == MAP_FAILED) LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", size, fd); } static int shmIsSizeValid(int fd, size_t size) { struct stat st; - if (fstat(fd, &st) == -1) { + if UNLIKELY (fstat(fd, &st) == -1) { LOGM(ERR, "Couldn't get stat for fd {} of shm client", fd); return 0; } @@ -111,10 +111,10 @@ static int shmIsSizeValid(int fd, size_t size) { } CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t size_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; - if (!shmIsSizeValid(fd_, size_)) { + if UNLIKELY (!shmIsSizeValid(fd_, size_)) { resource_->error(-1, "The size of the file is not big enough for the shm pool"); return; } @@ -125,11 +125,11 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); }); resource->setResize([this](CWlShmPool* r, int32_t size_) { - if (size_ < (int32_t)pool->size) { + if UNLIKELY (size_ < (int32_t)pool->size) { r->error(-1, "Shrinking a shm pool is illegal"); return; } - if (!shmIsSizeValid(pool->fd, size_)) { + if UNLIKELY (!shmIsSizeValid(pool->fd, size_)) { r->error(-1, "The size of the file is not big enough for the shm pool"); return; } @@ -138,24 +138,24 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t }); resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) { - if (!pool || !pool->data) { + if UNLIKELY (!pool || !pool->data) { r->error(-1, "The provided shm pool failed to allocate properly"); return; } - if (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) { + if UNLIKELY (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) { r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid"); return; } - if (offset < 0 || w <= 0 || h <= 0 || stride <= 0) { + if UNLIKELY (offset < 0 || w <= 0 || h <= 0 || stride <= 0) { r->error(WL_SHM_ERROR_INVALID_STRIDE, "Invalid stride, w, h, or offset"); return; } const auto RESOURCE = PROTO::shm->m_vBuffers.emplace_back(makeShared(self.lock(), id, offset, Vector2D{w, h}, stride, fmt)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::shm->m_vBuffers.pop_back(); return; @@ -165,7 +165,7 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP resource_, int fd_, size_t RESOURCE->resource->buffer = RESOURCE; }); - if (pool->data == MAP_FAILED) + if UNLIKELY (pool->data == MAP_FAILED) resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd"); } @@ -174,7 +174,7 @@ bool CWLSHMPoolResource::good() { } CWLSHMResource::CWLSHMResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); }); @@ -182,7 +182,7 @@ CWLSHMResource::CWLSHMResource(SP resource_) : resource(resource_) { resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) { const auto RESOURCE = PROTO::shm->m_vPools.emplace_back(makeShared(makeShared(r->client(), r->version(), id), fd, size)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::shm->m_vPools.pop_back(); return; @@ -221,7 +221,7 @@ void CWLSHMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, ui const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/core/Subcompositor.cpp b/src/protocols/core/Subcompositor.cpp index 46e20305..4edb07ff 100644 --- a/src/protocols/core/Subcompositor.cpp +++ b/src/protocols/core/Subcompositor.cpp @@ -4,7 +4,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP resource_, SP surface_, SP parent_) : surface(surface_), parent(parent_), resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlSubsurface* r) { destroy(); }); @@ -142,7 +142,7 @@ SP CWLSubsurfaceResource::t1Parent() { } CWLSubcompositorResource::CWLSubcompositorResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); }); @@ -152,12 +152,12 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP resource auto SURF = CWLSurfaceResource::fromResource(surface); auto PARENT = CWLSurfaceResource::fromResource(parent); - if (!SURF || !PARENT || SURF == PARENT) { + if UNLIKELY (!SURF || !PARENT || SURF == PARENT) { r->error(WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Invalid surface/parent"); return; } - if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { + if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) { r->error(-1, "Surface already has a different role"); return; } @@ -170,7 +170,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP resource } else t1Parent = PARENT; - if (t1Parent == SURF) { + if UNLIKELY (t1Parent == SURF) { r->error(WL_SUBCOMPOSITOR_ERROR_BAD_PARENT, "Bad parent, t1 parent == surf"); return; } @@ -178,7 +178,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP resource const auto RESOURCE = PROTO::subcompositor->m_vSurfaces.emplace_back(makeShared(makeShared(r->client(), r->version(), id), SURF, PARENT)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); PROTO::subcompositor->m_vSurfaces.pop_back(); return; @@ -205,7 +205,7 @@ CWLSubcompositorProtocol::CWLSubcompositorProtocol(const wl_interface* iface, co void CWLSubcompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); m_vManagers.pop_back(); return; diff --git a/src/protocols/types/DMABuffer.cpp b/src/protocols/types/DMABuffer.cpp index 9f31f6a2..3f53225c 100644 --- a/src/protocols/types/DMABuffer.cpp +++ b/src/protocols/types/DMABuffer.cpp @@ -17,11 +17,11 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs auto eglImage = g_pHyprOpenGL->createEGLImage(attrs); - if (!eglImage) { + if UNLIKELY (!eglImage) { Debug::log(ERR, "CDMABuffer: failed to import EGLImage, retrying as implicit"); attrs.modifier = DRM_FORMAT_MOD_INVALID; eglImage = g_pHyprOpenGL->createEGLImage(attrs); - if (!eglImage) { + if UNLIKELY (!eglImage) { Debug::log(ERR, "CDMABuffer: failed to import EGLImage"); return; } @@ -31,7 +31,7 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs opaque = NFormatUtils::isFormatOpaque(attrs.format); success = texture->m_iTexID; - if (!success) + if UNLIKELY (!success) Debug::log(ERR, "Failed to create a dmabuf: texture is null"); } diff --git a/src/protocols/types/WLBuffer.cpp b/src/protocols/types/WLBuffer.cpp index a9e6400a..4bd115a2 100644 --- a/src/protocols/types/WLBuffer.cpp +++ b/src/protocols/types/WLBuffer.cpp @@ -6,7 +6,7 @@ #include CWLBufferResource::CWLBufferResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CWlBuffer* r) {