Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fbce50e

Browse files
committedMay 13, 2024
avoid copying bufs
1 parent 8f4d559 commit fbce50e

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed
 

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

Lines changed: 42 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>
@@ -64,6 +65,22 @@ namespace Aws
6465
}
6566
}
6667

68+
/**
69+
* Create new array with a pointer and its dimensions.
70+
*
71+
* @param m_size the capacity of the array.
72+
* @param m_length the current length of the array,
73+
* @param m_data the data that the array points to.
74+
*/
75+
Array(size_t m_size,
76+
size_t m_length,
77+
UniqueArrayPtr<T> m_data)
78+
: m_size(m_size),
79+
m_length(m_length),
80+
m_data(std::move(m_data))
81+
{
82+
}
83+
6784
/**
6885
* Merge multiple arrays into one
6986
*/
@@ -114,7 +131,7 @@ namespace Aws
114131
}
115132

116133
//move c_tor
117-
Array(Array&& other) :
134+
Array(Array&& other) noexcept:
118135
m_size(other.m_size),
119136
m_length(other.m_length),
120137
m_data(std::move(other.m_data))
@@ -150,7 +167,7 @@ namespace Aws
150167
return *this;
151168
}
152169

153-
Array& operator=(Array&& other)
170+
Array& operator=(Array&& other) noexcept
154171
{
155172
m_size = other.m_size;
156173
m_length = other.m_length;
@@ -258,6 +275,29 @@ namespace Aws
258275
CryptoBuffer(CryptoBuffer&& other) : ByteBuffer(std::move(other)) {}
259276
CryptoBuffer& operator=(const CryptoBuffer&) = default;
260277
CryptoBuffer& operator=(CryptoBuffer&& other) { ByteBuffer::operator=(std::move(other)); return *this; }
278+
279+
CryptoBuffer(Crt::ByteBuf&& other) noexcept : ByteBuffer(
280+
other.len,
281+
other.len,
282+
nullptr)
283+
{
284+
m_data.reset(other.buffer);
285+
other.capacity = 0;
286+
other.len = 0;
287+
other.allocator = nullptr;
288+
}
289+
290+
CryptoBuffer& operator=(Crt::ByteBuf&& other) noexcept
291+
{
292+
m_size = other.len;
293+
m_length = other.len;
294+
m_data.reset(other.buffer);
295+
other.capacity = 0;
296+
other.len = 0;
297+
other.allocator = nullptr;
298+
return *this;
299+
}
300+
261301
bool operator==(const CryptoBuffer& other) const { return ByteBuffer::operator==(other); }
262302
bool operator!=(const CryptoBuffer& other) const { return ByteBuffer::operator!=(other); }
263303

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ 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 {std::move(resultBuffer)};
4240
}
4341
Crt::ByteBufDelete(resultBuffer);
4442
return {0};
@@ -52,9 +50,7 @@ namespace Aws
5250
{
5351
auto tagCur = m_cipher.GetTag();
5452
m_tag = CryptoBuffer(tagCur.ptr, tagCur.len);
55-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
56-
Crt::ByteBufDelete(resultBuffer);
57-
return result;
53+
return {std::move(resultBuffer)};
5854
}
5955
Crt::ByteBufDelete(resultBuffer);
6056
return {0};
@@ -69,9 +65,7 @@ namespace Aws
6965

7066
if (m_cipher.Decrypt(toDecrypt, resultBuffer))
7167
{
72-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
73-
Crt::ByteBufDelete(resultBuffer);
74-
return result;
68+
return {std::move(resultBuffer)};
7569
}
7670
Crt::ByteBufDelete(resultBuffer);
7771
return (0);
@@ -83,9 +77,7 @@ namespace Aws
8377

8478
if (m_cipher.FinalizeDecryption(resultBuffer))
8579
{
86-
CryptoBuffer result{resultBuffer.buffer, resultBuffer.len};
87-
Crt::ByteBufDelete(resultBuffer);
88-
return result;
80+
return {std::move(resultBuffer)};
8981
}
9082
Crt::ByteBufDelete(resultBuffer);
9183
return {0};

0 commit comments

Comments
 (0)
Please sign in to comment.