diff options
author | Tom Englund <[email protected]> | 2024-06-17 17:37:36 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-17 17:37:36 +0200 |
commit | 28ce0e0f804de50f75eab797bc404c1be0b54442 (patch) | |
tree | 5f8dc0161f41c52837bbbb9992bc86ec19b3a95b | |
parent | a9c7a0830fd9a8b9fc4065f1cd654efd1326691a (diff) | |
download | Hyprland-28ce0e0f804de50f75eab797bc404c1be0b54442.tar.gz Hyprland-28ce0e0f804de50f75eab797bc404c1be0b54442.zip |
misc: a few compiler level performance optimisations (#6559)
* window: use const references instead of copies
use const references instead of wasteful copies and make the = operator
check for self assignment and return early. also use const in all the
other operators.
* listener: pass std::function as const reference
instead of copies pass the std::functions as const references.
* config: dont unnecessarily convert to c_str
getHyprlangConfigValuePtr wants an std::string and we already have an
std::string, dont convert it to a c_str only for it to be converted back
to an std::string.
* buffer: pass attributes as const reference
pass attributes as const reference instead of copies.
-rw-r--r-- | src/config/ConfigValue.hpp | 2 | ||||
-rw-r--r-- | src/desktop/Window.hpp | 30 | ||||
-rw-r--r-- | src/helpers/WLListener.cpp | 4 | ||||
-rw-r--r-- | src/helpers/WLListener.hpp | 4 | ||||
-rw-r--r-- | src/protocols/types/DMABuffer.cpp | 2 | ||||
-rw-r--r-- | src/protocols/types/DMABuffer.hpp | 2 |
6 files changed, 24 insertions, 20 deletions
diff --git a/src/config/ConfigValue.hpp b/src/config/ConfigValue.hpp index 72accd67..fc8abb4b 100644 --- a/src/config/ConfigValue.hpp +++ b/src/config/ConfigValue.hpp @@ -11,7 +11,7 @@ template <typename T> class CConfigValue { public: CConfigValue(const std::string& val) { - const auto PVHYPRLANG = g_pConfigManager->getHyprlangConfigValuePtr(val.c_str()); + const auto PVHYPRLANG = g_pConfigManager->getHyprlangConfigValuePtr(val); p_ = PVHYPRLANG->getDataStaticPtr(); diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index 16bf297c..3f387d31 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -62,18 +62,22 @@ class IWindowTransformer; template <typename T> class CWindowOverridableVar { public: - CWindowOverridableVar(T val) { + CWindowOverridableVar(T const& val) { value = val; } ~CWindowOverridableVar() = default; - CWindowOverridableVar<T>& operator=(CWindowOverridableVar<T> other) { - if (locked) + CWindowOverridableVar<T>& operator=(CWindowOverridableVar<T> const& other) { + // Self-assignment check + if (this == &other) return *this; - locked = other.locked; - value = other.value; + // Check if the current object is locked + if (!locked) { + locked = other.locked; + value = other.value; + } return *this; } @@ -85,36 +89,36 @@ class CWindowOverridableVar { return other; } - void forceSetIgnoreLocked(T val, bool lock = false) { + void forceSetIgnoreLocked(T const& val, bool lock = false) { value = val; locked = lock; } - T operator*(T& other) { + T operator*(T const& other) { return value * other; } - T operator+(T& other) { + T operator+(T const& other) { return value + other; } - bool operator==(T& other) { + bool operator==(T const& other) { return other == value; } - bool operator>=(T& other) { + bool operator>=(T const& other) { return value >= other; } - bool operator<=(T& other) { + bool operator<=(T const& other) { return value <= other; } - bool operator>(T& other) { + bool operator>(T const& other) { return value > other; } - bool operator<(T& other) { + bool operator<(T const& other) { return value < other; } diff --git a/src/helpers/WLListener.cpp b/src/helpers/WLListener.cpp index 978ff034..2ea5c0b6 100644 --- a/src/helpers/WLListener.cpp +++ b/src/helpers/WLListener.cpp @@ -18,7 +18,7 @@ void handleWrapped(wl_listener* listener, void* data) { g_pWatchdog->endWatching(); } -CHyprWLListener::CHyprWLListener(wl_signal* pSignal, std::function<void(void*, void*)> callback, void* pOwner) { +CHyprWLListener::CHyprWLListener(wl_signal* pSignal, std::function<void(void*, void*)> const& callback, void* pOwner) { initCallback(pSignal, callback, pOwner); } @@ -44,7 +44,7 @@ bool CHyprWLListener::isConnected() { return !wl_list_empty(&m_swWrapper.m_sListener.link); } -void CHyprWLListener::initCallback(wl_signal* pSignal, std::function<void(void*, void*)> callback, void* pOwner, std::string author) { +void CHyprWLListener::initCallback(wl_signal* pSignal, std::function<void(void*, void*)> const& callback, void* pOwner, std::string author) { if (isConnected()) { Debug::log(ERR, "Tried to connect a listener twice?!"); return; diff --git a/src/helpers/WLListener.hpp b/src/helpers/WLListener.hpp index d5d925b0..621458e6 100644 --- a/src/helpers/WLListener.hpp +++ b/src/helpers/WLListener.hpp @@ -6,7 +6,7 @@ class CHyprWLListener { public: - CHyprWLListener(wl_signal*, std::function<void(void*, void*)>, void* owner); + CHyprWLListener(wl_signal*, std::function<void(void*, void*)> const&, void* owner); CHyprWLListener(); ~CHyprWLListener(); @@ -15,7 +15,7 @@ class CHyprWLListener { CHyprWLListener& operator=(const CHyprWLListener&) = delete; CHyprWLListener& operator=(CHyprWLListener&&) = delete; - void initCallback(wl_signal*, std::function<void(void*, void*)>, void* owner, std::string author = ""); + void initCallback(wl_signal*, std::function<void(void*, void*)> const&, void* owner, std::string author = ""); void removeCallback(); diff --git a/src/protocols/types/DMABuffer.cpp b/src/protocols/types/DMABuffer.cpp index f26328e9..7c3a9886 100644 --- a/src/protocols/types/DMABuffer.cpp +++ b/src/protocols/types/DMABuffer.cpp @@ -3,7 +3,7 @@ #include "../../render/Renderer.hpp" #include "../../helpers/Format.hpp" -CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs attrs_) : attrs(attrs_) { +CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs const& attrs_) : attrs(attrs_) { g_pHyprRenderer->makeEGLCurrent(); listeners.resourceDestroy = events.destroy.registerListener([this](std::any d) { diff --git a/src/protocols/types/DMABuffer.hpp b/src/protocols/types/DMABuffer.hpp index dac89493..d07840b7 100644 --- a/src/protocols/types/DMABuffer.hpp +++ b/src/protocols/types/DMABuffer.hpp @@ -4,7 +4,7 @@ class CDMABuffer : public IWLBuffer { public: - CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs attrs_); + CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs const& attrs_); virtual ~CDMABuffer(); virtual eBufferCapability caps(); |