summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-06-19 14:51:11 -0700
committerSteven Moreland <smoreland@google.com>2019-06-20 19:32:23 +0000
commitdfbedb8ffb429427bf7d3dbdfd5c3fe002f02718 (patch)
treee03d724abf519e3297a396a728016dbca952fe92 /base
parent5b8eb35645ec7e329fe0c6462125445fc5a3697c (diff)
downloadlibhidl-dfbedb8ffb429427bf7d3dbdfd5c3fe002f02718.tar.gz
hidl_vec: move elements on resize
To avoid extra copies. Doing this also requires adding move constructors and move assignment operators to hidl_array. Bug: 135207394 Test: libhidl_test Test: hidl_test Test: reduces image size on aosp_walleye $ cat installed-files-before.txt | awk '{s+=$1}END{print s}' 1135438223 $ cat installed-files-after.txt | awk '{s+=$1}END{print s}' 1135434327 Change-Id: I231f5c9cc959b605e6f102ff7217f338c95d5d5e
Diffstat (limited to 'base')
-rw-r--r--base/include/hidl/HidlSupport.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 79dd992..44691e6 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -508,7 +508,7 @@ struct hidl_vec {
T *newBuffer = new T[size];
for (size_t i = 0; i < std::min(static_cast<uint32_t>(size), mSize); ++i) {
- newBuffer[i] = mBuffer[i];
+ newBuffer[i] = std::move(mBuffer[i]);
}
if (mOwnsBuffer) {
@@ -729,6 +729,8 @@ struct hidl_array {
using std_array_type = typename details::std_array<T, SIZE1, SIZES...>::type;
hidl_array() = default;
+ hidl_array(const hidl_array&) noexcept = default;
+ hidl_array(hidl_array&&) noexcept = default;
// Copies the data from source, using T::operator=(const T &).
hidl_array(const T *source) {
@@ -743,6 +745,9 @@ struct hidl_array {
modifier = array;
}
+ hidl_array& operator=(const hidl_array&) noexcept = default;
+ hidl_array& operator=(hidl_array&&) noexcept = default;
+
T *data() { return mBuffer; }
const T *data() const { return mBuffer; }
@@ -795,6 +800,8 @@ struct hidl_array<T, SIZE1> {
using std_array_type = typename details::std_array<T, SIZE1>::type;
hidl_array() = default;
+ hidl_array(const hidl_array&) noexcept = default;
+ hidl_array(hidl_array&&) noexcept = default;
// Copies the data from source, using T::operator=(const T &).
hidl_array(const T *source) {
@@ -806,6 +813,9 @@ struct hidl_array<T, SIZE1> {
// Copies the data from the given std::array, using T::operator=(const T &).
hidl_array(const std_array_type &array) : hidl_array(array.data()) {}
+ hidl_array& operator=(const hidl_array&) noexcept = default;
+ hidl_array& operator=(hidl_array&&) noexcept = default;
+
T *data() { return mBuffer; }
const T *data() const { return mBuffer; }