From 498e20561f065b656f08b8206a5018548fa57cf5 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 2 Jul 2023 19:29:04 +0200 Subject: [PATCH] libluna: Add release_data() overloads to Buffer and Vector This can be used to transfer the underlying data to a String object without copying. --- libluna/include/luna/Buffer.h | 2 ++ libluna/include/luna/Vector.h | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/libluna/include/luna/Buffer.h b/libluna/include/luna/Buffer.h index 54b0fc46..405c7dd9 100644 --- a/libluna/include/luna/Buffer.h +++ b/libluna/include/luna/Buffer.h @@ -31,6 +31,8 @@ class Buffer return m_data; } + u8* release_data(); + u8* end() { return m_data + m_size; diff --git a/libluna/include/luna/Vector.h b/libluna/include/luna/Vector.h index c5ffda56..076e4ac2 100644 --- a/libluna/include/luna/Vector.h +++ b/libluna/include/luna/Vector.h @@ -134,6 +134,14 @@ template class Vector return m_data; } + T* release_data() + { + T* data = m_data; + m_data = nullptr; + m_size = m_capacity = 0; + return data; + } + Slice slice() { return { m_data, m_size };