diff options
author | sfan5 <sfan5@live.de> | 2021-09-17 18:14:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 18:14:25 +0200 |
commit | fd8a8501bc26dfca2a93d51000867b8592210040 (patch) | |
tree | 2555456796bc15f7ef0f2bc24c08b9848b874b4e /src/util/pointer.h | |
parent | ea250ff5c57301b6ea3e529c811484c743c1fde1 (diff) | |
download | minetest-fd8a8501bc26dfca2a93d51000867b8592210040.tar.gz minetest-fd8a8501bc26dfca2a93d51000867b8592210040.tar.bz2 minetest-fd8a8501bc26dfca2a93d51000867b8592210040.zip |
Shave off buffer copies in networking code (#11607)
Diffstat (limited to 'src/util/pointer.h')
-rw-r--r-- | src/util/pointer.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util/pointer.h b/src/util/pointer.h index d29ec8739..7fc5de551 100644 --- a/src/util/pointer.h +++ b/src/util/pointer.h @@ -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() { |