core: add LIKELY and UNLIKELY macros

helps the compiler optimize
This commit is contained in:
vaxerski 2025-01-17 18:21:34 +01:00
parent 2bad73354a
commit b7a3c45269
58 changed files with 395 additions and 396 deletions

View file

@ -17,7 +17,7 @@ CFocusGrabSurfaceState::~CFocusGrabSurfaceState() {
}
CFocusGrab::CFocusGrab(SP<CHyprlandFocusGrabV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
grab = makeShared<CSeatGrab>();
@ -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<CWLSurfaceResource> 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<CFocusGrabSurfaceState>(this, surface));
}
}
void CFocusGrab::removeSurface(SP<CWLSurfaceResource> 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<CFocusGrab>(makeShared<CHyprlandFocusGrabV1>(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();
}