libluna: Add release_data() overloads to Buffer and Vector

This can be used to transfer the underlying data to a String object without copying.
This commit is contained in:
apio 2023-07-02 19:29:04 +02:00
parent d363d5e915
commit 498e20561f
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 10 additions and 0 deletions

View File

@ -31,6 +31,8 @@ class Buffer
return m_data; return m_data;
} }
u8* release_data();
u8* end() u8* end()
{ {
return m_data + m_size; return m_data + m_size;

View File

@ -134,6 +134,14 @@ template <typename T> class Vector
return m_data; return m_data;
} }
T* release_data()
{
T* data = m_data;
m_data = nullptr;
m_size = m_capacity = 0;
return data;
}
Slice<T> slice() Slice<T> slice()
{ {
return { m_data, m_size }; return { m_data, m_size };