aboutsummaryrefslogtreecommitdiffstats
path: root/src/Buffer.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-03-06 22:53:36 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-03-06 22:53:36 +0100
commit56dfbcd73529ee6dc42a17a139c9ceaccf1def3d (patch)
tree47580fcfa894fca04805f670ec6acf30a08a6f5d /src/Buffer.cpp
parent5bea9241b246cfc4b9abef3d265a96d52a377c37 (diff)
downloaddabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.gz
dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.tar.bz2
dabmod-56dfbcd73529ee6dc42a17a139c9ceaccf1def3d.zip
Avoid copies in ThreadsafeQueue and Buffer
Diffstat (limited to 'src/Buffer.cpp')
-rw-r--r--src/Buffer.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index e96b8d6..002c1eb 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -77,6 +77,12 @@ Buffer::~Buffer()
}
}
+void Buffer::swap(Buffer& other)
+{
+ std::swap(m_len, other.m_len);
+ std::swap(m_capacity, other.m_capacity);
+ std::swap(m_data, other.m_data);
+}
Buffer& Buffer::operator=(const Buffer& other)
{
@@ -142,6 +148,13 @@ void Buffer::setData(const void *data, size_t len)
appendData(data, len);
}
+uint8_t Buffer::operator[](size_t i) const
+{
+ if (i >= m_len) {
+ throw std::out_of_range("index out of range");
+ }
+ return reinterpret_cast<uint8_t*>(m_data)[i];
+}
void Buffer::appendData(const void *data, size_t len)
{
@@ -153,3 +166,8 @@ void Buffer::appendData(const void *data, size_t len)
}
}
+void swap(Buffer& buf1, Buffer& buf2)
+{
+ buf1.swap(buf2);
+}
+