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/GlobalShortcuts.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/protocols/GlobalShortcuts.cpp') diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp index ca67f063..6fac2d7f 100644 --- a/src/protocols/GlobalShortcuts.cpp +++ b/src/protocols/GlobalShortcuts.cpp @@ -1,7 +1,7 @@ #include "GlobalShortcuts.hpp" CShortcutClient::CShortcutClient(SP resource_) : resource(resource_) { - if (!good()) + if UNLIKELY (!good()) return; resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); }); @@ -9,7 +9,7 @@ CShortcutClient::CShortcutClient(SP resource_ resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description, const char* trigger_description) { - if (PROTO::globalShortcuts->isTaken(id, app_id)) { + if UNLIKELY (PROTO::globalShortcuts->isTaken(id, app_id)) { resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken"); return; } @@ -20,7 +20,7 @@ CShortcutClient::CShortcutClient(SP resource_ PSHORTCUT->appid = app_id; PSHORTCUT->shortcut = shortcut; - if (!PSHORTCUT->resource->resource()) { + if UNLIKELY (!PSHORTCUT->resource->resource()) { PSHORTCUT->resource->noMemory(); shortcuts.pop_back(); return; @@ -41,7 +41,7 @@ CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, co void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { const auto RESROUCE = m_vClients.emplace_back(makeShared(makeShared(client, ver, id))); - if (!RESROUCE->good()) { + if UNLIKELY (!RESROUCE->good()) { wl_client_post_no_memory(client); m_vClients.pop_back(); return; -- cgit v1.2.3