1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Shave off buffer copies in networking code (#11607)

This commit is contained in:
sfan5 2021-09-17 18:14:25 +02:00 committed by GitHub
parent ea250ff5c5
commit fd8a8501bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 126 additions and 92 deletions

View file

@ -51,6 +51,19 @@ public:
else
data = NULL;
}
Buffer(Buffer &&buffer)
{
m_size = buffer.m_size;
if(m_size != 0)
{
data = buffer.data;
buffer.data = nullptr;
buffer.m_size = 0;
}
else
data = nullptr;
}
// Copies whole buffer
Buffer(const T *t, unsigned int size)
{
m_size = size;
@ -62,10 +75,12 @@ public:
else
data = NULL;
}
~Buffer()
{
drop();
}
Buffer& operator=(const Buffer &buffer)
{
if(this == &buffer)
@ -81,6 +96,23 @@ public:
data = NULL;
return *this;
}
Buffer& operator=(Buffer &&buffer)
{
if(this == &buffer)
return *this;
drop();
m_size = buffer.m_size;
if(m_size != 0)
{
data = buffer.data;
buffer.data = nullptr;
buffer.m_size = 0;
}
else
data = nullptr;
return *this;
}
T & operator[](unsigned int i) const
{
return data[i];
@ -89,10 +121,12 @@ public:
{
return data;
}
unsigned int getSize() const
{
return m_size;
}
private:
void drop()
{