From b7a3c4526990d6601ff2cac748ff860cda6bc16d Mon Sep 17 00:00:00 2001 From: vaxerski Date: Fri, 17 Jan 2025 18:21:34 +0100 Subject: core: add LIKELY and UNLIKELY macros helps the compiler optimize --- src/protocols/XDGShell.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/protocols/XDGShell.cpp') 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; -- cgit v1.2.3