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