mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-17 06:00:03 +02:00
Prevent unnecessary copies in ScopedValueCache
This commit is contained in:
+6
-5
@@ -144,19 +144,20 @@ class ScopedValueCache {
|
|||||||
class Guard {
|
class Guard {
|
||||||
public:
|
public:
|
||||||
Guard(std::optional<T>& cached_value) : cached_value(cached_value) {}
|
Guard(std::optional<T>& cached_value) : cached_value(cached_value) {}
|
||||||
|
|
||||||
~Guard() {
|
~Guard() {
|
||||||
if (is_active) {
|
if (is_active) {
|
||||||
cached_value.reset();
|
cached_value.get().reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Guard(const Guard&) = delete;
|
Guard(const Guard&) = delete;
|
||||||
Guard& operator=(const Guard&) = delete;
|
Guard& operator=(const Guard&) = delete;
|
||||||
|
|
||||||
Guard(Guard&& o) : cached_value(o.cached_value) { o.is_active = false; }
|
Guard(Guard&& o) : cached_value(std::move(o.cached_value)) {
|
||||||
|
o.is_active = false;
|
||||||
|
}
|
||||||
Guard& operator=(Guard&& o) {
|
Guard& operator=(Guard&& o) {
|
||||||
cached_value = o.cache;
|
cached_value = std::move(o.cached_value);
|
||||||
o.is_active = false;
|
o.is_active = false;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -164,7 +165,7 @@ class ScopedValueCache {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_active = true;
|
bool is_active = true;
|
||||||
std::optional<T>& cached_value;
|
std::reference_wrapper<std::optional<T>> cached_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user