From a0f66bdad2b247e2742414843931a5351fda5977 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 6 Sep 2024 21:19:59 -0500 Subject: [PATCH] [ox/std] Add IString::unsafeResize (synced from ba4540e43ff0d3f0653f41c9b712e52b1de874f6) --- src/ox/std/istring.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ox/std/istring.hpp b/src/ox/std/istring.hpp index 7ffee5e49..83dea2554 100644 --- a/src/ox/std/istring.hpp +++ b/src/ox/std/istring.hpp @@ -81,6 +81,11 @@ class IString { constexpr ox::Error resize(size_t sz) noexcept; + /** + * Resizes without clearing memory between current end and new end. + */ + constexpr ox::Error unsafeResize(size_t sz) noexcept; + /** * Returns the capacity of bytes for this string. */ @@ -220,6 +225,15 @@ constexpr ox::Error IString::resize(size_t sz) noexcept { return {}; } +template +constexpr ox::Error IString::unsafeResize(size_t sz) noexcept { + if (sz > StrCap) [[unlikely]] { + return OxError(1, "Trying to extend IString beyond its cap"); + } + m_size = sz; + return {}; +} + template struct MaybeView> { using type = ox::StringView;