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/PointerConstraints.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/protocols/PointerConstraints.cpp') 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(); -- cgit v1.2.3