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