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/XDGDialog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/protocols/XDGDialog.cpp') diff --git a/src/protocols/XDGDialog.cpp b/src/protocols/XDGDialog.cpp index 3f58f326..675d4e78 100644 --- a/src/protocols/XDGDialog.cpp +++ b/src/protocols/XDGDialog.cpp @@ -5,7 +5,7 @@ #include CXDGDialogV1Resource::CXDGDialogV1Resource(SP resource_, SP toplevel_) : resource(resource_), toplevel(toplevel_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXdgDialogV1* r) { PROTO::xdgDialog->destroyResource(this); }); @@ -23,11 +23,11 @@ CXDGDialogV1Resource::CXDGDialogV1Resource(SP resource_, SPparent || !toplevel->parent->owner) + if UNLIKELY (!toplevel || !toplevel->parent || !toplevel->parent->owner) return; auto HLSurface = CWLSurface::fromResource(toplevel->parent->owner->surface.lock()); - if (!HLSurface || !HLSurface->getWindow()) + if UNLIKELY (!HLSurface || !HLSurface->getWindow()) return; g_pCompositor->updateWindowAnimatedDecorationValues(HLSurface->getWindow()); @@ -38,7 +38,7 @@ bool CXDGDialogV1Resource::good() { } CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setDestroy([this](CXdgWmDialogV1* r) { PROTO::xdgDialog->destroyResource(this); }); @@ -46,14 +46,14 @@ CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP reso resource->setGetXdgDialog([](CXdgWmDialogV1* r, uint32_t id, wl_resource* toplevel) { auto tl = CXDGToplevelResource::fromResource(toplevel); - if (!tl) { + if UNLIKELY (!tl) { r->error(-1, "Toplevel inert"); return; } const auto RESOURCE = PROTO::xdgDialog->m_vDialogs.emplace_back(makeShared(makeShared(r->client(), r->version(), id), tl)); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { r->noMemory(); return; } @@ -73,7 +73,7 @@ CXDGDialogProtocol::CXDGDialogProtocol(const wl_interface* iface, const int& ver void CXDGDialogProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESOURCE = m_vManagers.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESOURCE->good()) { + if UNLIKELY (!RESOURCE->good()) { wl_client_post_no_memory(client); return; } -- cgit v1.2.3