aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/desktop
diff options
context:
space:
mode:
authorTom Englund <[email protected]>2024-06-17 17:37:36 +0200
committerGitHub <[email protected]>2024-06-17 17:37:36 +0200
commit28ce0e0f804de50f75eab797bc404c1be0b54442 (patch)
tree5f8dc0161f41c52837bbbb9992bc86ec19b3a95b /src/desktop
parenta9c7a0830fd9a8b9fc4065f1cd654efd1326691a (diff)
downloadHyprland-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.
Diffstat (limited to 'src/desktop')
-rw-r--r--src/desktop/Window.hpp30
1 files changed, 17 insertions, 13 deletions
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;
}