libluna: Add the clear_data() method to Vector and use it to optimize Base64::decode
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This method clears the Vector's data without deallocating the backing buffer, so that it can be reused without reallocation.
This commit is contained in:
parent
d45e9e2a8c
commit
148c1c7341
@ -201,6 +201,13 @@ template <typename T> class Vector
|
|||||||
m_data = nullptr;
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear_data()
|
||||||
|
{
|
||||||
|
for (usize i = 0; i < m_size; i++) { m_data[i].~T(); }
|
||||||
|
|
||||||
|
m_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Result<Vector<T>> shallow_copy()
|
Result<Vector<T>> shallow_copy()
|
||||||
{
|
{
|
||||||
Vector<T> other;
|
Vector<T> other;
|
||||||
|
@ -118,6 +118,7 @@ namespace Base64
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector<char> chars_read;
|
Vector<char> chars_read;
|
||||||
|
TRY(chars_read.try_reserve(4));
|
||||||
|
|
||||||
for (const auto& c : data)
|
for (const auto& c : data)
|
||||||
{
|
{
|
||||||
@ -134,7 +135,7 @@ namespace Base64
|
|||||||
if (chars_read.size() == 4)
|
if (chars_read.size() == 4)
|
||||||
{
|
{
|
||||||
TRY(decode_base64_buffer(chars_read, buf));
|
TRY(decode_base64_buffer(chars_read, buf));
|
||||||
chars_read.clear();
|
chars_read.clear_data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user