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

@@ -10,7 +10,7 @@
#include <fcntl.h>
CWLTouchResource::CWLTouchResource(SP<CWlTouch> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
@@ -105,7 +105,7 @@ void CWLTouchResource::sendOrientation(int32_t id, double angle) {
}
CWLPointerResource::CWLPointerResource(SP<CWlPointer> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
@@ -292,7 +292,7 @@ void CWLPointerResource::sendAxisRelativeDirection(wl_pointer_axis axis, wl_poin
}
CWLKeyboardResource::CWLKeyboardResource(SP<CWlKeyboard> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
@@ -419,7 +419,7 @@ void CWLKeyboardResource::repeatInfo(uint32_t rate, uint32_t delayMs) {
}
CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSeat* r) {
@@ -436,7 +436,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetKeyboard([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vKeyboards.emplace_back(makeShared<CWLKeyboardResource>(makeShared<CWlKeyboard>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vKeyboards.pop_back();
return;
@@ -448,7 +448,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetPointer([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vPointers.emplace_back(makeShared<CWLPointerResource>(makeShared<CWlPointer>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vPointers.pop_back();
return;
@@ -460,7 +460,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetTouch([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vTouches.emplace_back(makeShared<CWLTouchResource>(makeShared<CWlTouch>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vTouches.pop_back();
return;
@@ -506,7 +506,7 @@ CWLSeatProtocol::CWLSeatProtocol(const wl_interface* iface, const int& ver, cons
void CWLSeatProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vSeatResources.emplace_back(makeShared<CWLSeatResource>(makeShared<CWlSeat>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vSeatResources.pop_back();
return;