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

@@ -34,7 +34,7 @@ void CWLCallbackResource::send(timespec* now) {
}
CWLRegionResource::CWLRegionResource(SP<CWlRegion> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@@ -56,7 +56,7 @@ SP<CWLRegionResource> CWLRegionResource::fromResource(wl_resource* res) {
}
CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@@ -187,20 +187,20 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end())
return;
if (!PROTO::outputs.contains(monitor->szName)) {
if UNLIKELY (!PROTO::outputs.contains(monitor->szName)) {
// can happen on unplug/replug
LOGM(ERR, "enter() called on a non-existent output global");
return;
}
if (PROTO::outputs.at(monitor->szName)->isDefunct()) {
if UNLIKELY (PROTO::outputs.at(monitor->szName)->isDefunct()) {
LOGM(ERR, "enter() called on a defunct output global");
return;
}
auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient);
if (!output || !output->getResource() || !output->getResource()->resource()) {
if UNLIKELY (!output || !output->getResource() || !output->getResource()->resource()) {
LOGM(ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->szName);
return;
}
@@ -211,12 +211,12 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
}
void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
if UNLIKELY (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
return;
auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient);
if (!output) {
if UNLIKELY (!output) {
LOGM(ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->szName);
return;
}
@@ -332,7 +332,7 @@ uint32_t CWLSurfaceResource::id() {
}
void CWLSurfaceResource::map() {
if (mapped)
if UNLIKELY (mapped)
return;
mapped = true;
@@ -346,7 +346,7 @@ void CWLSurfaceResource::map() {
}
void CWLSurfaceResource::unmap() {
if (!mapped)
if UNLIKELY (!mapped)
return;
mapped = false;
@@ -385,10 +385,10 @@ CBox CWLSurfaceResource::extends() {
}
Vector2D CWLSurfaceResource::sourceSize() {
if (!current.texture)
if UNLIKELY (!current.texture)
return {};
if (current.viewport.hasSource)
if UNLIKELY (current.viewport.hasSource)
return current.viewport.source.size();
Vector2D trc = current.transform % 2 == 1 ? Vector2D{current.bufferSize.y, current.bufferSize.x} : current.bufferSize;
@@ -396,7 +396,7 @@ Vector2D CWLSurfaceResource::sourceSize() {
}
CRegion CWLSurfaceResource::accumulateCurrentBufferDamage() {
if (!current.texture)
if UNLIKELY (!current.texture)
return {};
CRegion surfaceDamage = current.damage;
@@ -495,7 +495,7 @@ void CWLSurfaceResource::commitPendingState() {
void CWLSurfaceResource::updateCursorShm(CRegion damage) {
auto buf = current.buffer ? current.buffer->buffer : lastBuffer;
if (!buf)
if UNLIKELY (!buf)
return;
auto& shmData = CCursorSurfaceRole::cursorPixelData(self.lock());
@@ -545,7 +545,7 @@ void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor, bo
}
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlCompositor* r) { PROTO::compositor->destroyResource(this); });
@@ -553,7 +553,7 @@ CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : reso
resource->setCreateSurface([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vSurfaces.emplace_back(makeShared<CWLSurfaceResource>(makeShared<CWlSurface>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vSurfaces.pop_back();
return;
@@ -569,7 +569,7 @@ CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : reso
resource->setCreateRegion([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vRegions.emplace_back(makeShared<CWLRegionResource>(makeShared<CWlRegion>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vRegions.pop_back();
return;
@@ -592,7 +592,7 @@ CWLCompositorProtocol::CWLCompositorProtocol(const wl_interface* iface, const in
void CWLCompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLCompositorResource>(makeShared<CWlCompositor>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;