Skip to content

Commit 2982c1d

Browse files
committed
move to move ctor
1 parent 2865836 commit 2982c1d

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

src/aws-cpp-sdk-core/include/aws/core/utils/Array.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <aws/core/utils/memory/AWSMemory.h>
1111
#include <aws/core/utils/memory/stl/AWSVector.h>
12+
#include <aws/crt/Types.h>
1213
#include <memory>
1314
#include <cassert>
1415
#include <cstring>
@@ -114,7 +115,7 @@ namespace Aws
114115
}
115116

116117
//move c_tor
117-
Array(Array&& other) :
118+
Array(Array&& other) noexcept :
118119
m_size(other.m_size),
119120
m_length(other.m_length),
120121
m_data(std::move(other.m_data))
@@ -123,6 +124,16 @@ namespace Aws
123124
other.m_data = nullptr;
124125
}
125126

127+
explicit Array(Crt::ByteBuf&& other) noexcept :
128+
m_size(other.len),
129+
m_length(other.len),
130+
m_data(other.buffer)
131+
{
132+
other.capacity = 0;
133+
other.len = 0;
134+
other.buffer = nullptr;
135+
}
136+
126137
virtual ~Array() = default;
127138

128139
Array& operator=(const Array& other)
@@ -150,7 +161,7 @@ namespace Aws
150161
return *this;
151162
}
152163

153-
Array& operator=(Array&& other)
164+
Array& operator=(Array&& other) noexcept
154165
{
155166
m_size = other.m_size;
156167
m_length = other.m_length;
@@ -159,6 +170,15 @@ namespace Aws
159170
return *this;
160171
}
161172

173+
Array& operator=(Crt::ByteBuf&& other) noexcept
174+
{
175+
m_size = other.len;
176+
m_length = other.len;
177+
m_data.reset(other.buffer);
178+
179+
return *this;
180+
}
181+
162182
bool operator==(const Array& other) const
163183
{
164184
if (this == &other)
@@ -258,6 +278,8 @@ namespace Aws
258278
CryptoBuffer(CryptoBuffer&& other) : ByteBuffer(std::move(other)) {}
259279
CryptoBuffer& operator=(const CryptoBuffer&) = default;
260280
CryptoBuffer& operator=(CryptoBuffer&& other) { ByteBuffer::operator=(std::move(other)); return *this; }
281+
CryptoBuffer(Crt::ByteBuf&& other) noexcept : ByteBuffer(std::move(other)) {}
282+
CryptoBuffer& operator=(Crt::ByteBuf&& other) noexcept { ByteBuffer::operator=(std::move(other)); return *this; }
261283
bool operator==(const CryptoBuffer& other) const { return ByteBuffer::operator==(other); }
262284
bool operator!=(const CryptoBuffer& other) const { return ByteBuffer::operator!=(other); }
263285

src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSymmetricCipher.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ namespace Aws
3636

3737
if (m_cipher.Encrypt(toEncrypt, resultBuffer))
3838
{
39-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
40-
Crt::ByteBufDelete(resultBuffer);
41-
return result;
39+
return resultBuffer;
4240
}
43-
Crt::ByteBufDelete(resultBuffer);
4441
return {0};
4542
}
4643

@@ -52,11 +49,8 @@ namespace Aws
5249
{
5350
auto tagCur = m_cipher.GetTag();
5451
m_tag = CryptoBuffer(tagCur.ptr, tagCur.len);
55-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
56-
Crt::ByteBufDelete(resultBuffer);
57-
return result;
52+
return resultBuffer;
5853
}
59-
Crt::ByteBufDelete(resultBuffer);
6054
return {0};
6155
}
6256

@@ -69,11 +63,8 @@ namespace Aws
6963

7064
if (m_cipher.Decrypt(toDecrypt, resultBuffer))
7165
{
72-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
73-
Crt::ByteBufDelete(resultBuffer);
74-
return result;
66+
return resultBuffer;
7567
}
76-
Crt::ByteBufDelete(resultBuffer);
7768
return (0);
7869
}
7970

@@ -83,11 +74,8 @@ namespace Aws
8374

8475
if (m_cipher.FinalizeDecryption(resultBuffer))
8576
{
86-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
87-
Crt::ByteBufDelete(resultBuffer);
88-
return result;
77+
return resultBuffer;
8978
}
90-
Crt::ByteBufDelete(resultBuffer);
9179
return {0};
9280
}
9381

0 commit comments

Comments
 (0)