buffer: add move constructor and operator to CHLBufferReference (#13157)

add missing move constructor and operator, a lot of churn was done on
always copying CHLBufferReference, also add a self copy check.
This commit is contained in:
Tom Englund 2026-01-31 14:35:39 +01:00 committed by GitHub
parent 2ad7f6edd4
commit 4330b49a84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -59,6 +59,10 @@ CHLBufferReference::CHLBufferReference(const CHLBufferReference& other) : m_buff
m_buffer->lock();
}
CHLBufferReference::CHLBufferReference(CHLBufferReference&& other) noexcept : m_buffer(std::move(other.m_buffer)) {
;
}
CHLBufferReference::CHLBufferReference(SP<IHLBuffer> buffer_) : m_buffer(buffer_) {
if (m_buffer)
m_buffer->lock();
@ -70,6 +74,9 @@ CHLBufferReference::~CHLBufferReference() {
}
CHLBufferReference& CHLBufferReference::operator=(const CHLBufferReference& other) {
if (m_buffer == other.m_buffer)
return *this; // same buffer, do nothing
if (other.m_buffer)
other.m_buffer->lock();
if (m_buffer)
@ -78,6 +85,16 @@ CHLBufferReference& CHLBufferReference::operator=(const CHLBufferReference& othe
return *this;
}
CHLBufferReference& CHLBufferReference::operator=(CHLBufferReference&& other) {
if (this != &other) {
if (m_buffer)
m_buffer->unlock();
m_buffer = other.m_buffer;
other.m_buffer = nullptr;
}
return *this;
}
bool CHLBufferReference::operator==(const CHLBufferReference& other) const {
return m_buffer == other.m_buffer;
}

View file

@ -49,10 +49,13 @@ class CHLBufferReference {
public:
CHLBufferReference();
CHLBufferReference(const CHLBufferReference& other);
CHLBufferReference(CHLBufferReference&& other) noexcept;
CHLBufferReference(SP<IHLBuffer> buffer);
~CHLBufferReference();
CHLBufferReference& operator=(const CHLBufferReference& other);
CHLBufferReference& operator=(CHLBufferReference&& other);
bool operator==(const CHLBufferReference& other) const;
bool operator==(const SP<IHLBuffer>& other) const;
bool operator==(const SP<Aquamarine::IBuffer>& other) const;