summaryrefslogtreecommitdiff
path: root/src/protocols/core/Compositor.cpp
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2025-01-17 18:21:34 +0100
committervaxerski <vaxry@vaxry.net>2025-01-17 18:56:39 +0100
commitb7a3c4526990d6601ff2cac748ff860cda6bc16d (patch)
tree425c6afa0bc35f7f370a666bd7a81214a6e9475a /src/protocols/core/Compositor.cpp
parent2bad73354a5dbb9be8ba9a39b6238017a216a25b (diff)
core: add LIKELY and UNLIKELY macros
helps the compiler optimize
Diffstat (limited to 'src/protocols/core/Compositor.cpp')
-rw-r--r--src/protocols/core/Compositor.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp
index e1d6ef7d..93683993 100644
--- a/src/protocols/core/Compositor.cpp
+++ b/src/protocols/core/Compositor.cpp
@@ -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;