Add move constructor/assignment operator to hidl_memory
Bug: 34093434
Test: hidl_test passes
Change-Id: I6bb7e2e3c914040daa8d72d9a86a5a3d3f8338e5
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 2abdf1b..37f40c4 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -265,11 +265,12 @@
void hidl_string::moveFrom(hidl_string &&other) {
// assume my resources are freed.
- mBuffer = other.mBuffer;
+ mBuffer = std::move(other.mBuffer);
mSize = other.mSize;
mOwnsBuffer = other.mOwnsBuffer;
other.mOwnsBuffer = false;
+ other.clear();
}
void hidl_string::clear() {
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index d22c257..92a0e96 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -234,7 +234,23 @@
return *this;
}
- // TODO move constructor/move assignment
+ // move constructor
+ hidl_memory(hidl_memory&& other) {
+ *this = std::move(other);
+ }
+
+ // move assignment
+ hidl_memory &operator=(hidl_memory &&other) {
+ if (this != &other) {
+ mHandle = std::move(other.mHandle);
+ mSize = other.mSize;
+ mName = std::move(other.mName);
+ other.mSize = 0;
+ }
+
+ return *this;
+ }
+
~hidl_memory() {
}