summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/fud_string.hpp34
-rw-r--r--include/fud_vector.hpp5
2 files changed, 21 insertions, 18 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index 59c434a..86261c4 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -251,6 +251,17 @@ class String {
return SsoBufSize - 1U;
}
+ /** \brief Returns the remaining capacity for characters excluding the null
+ * terminating byte. */
+ [[nodiscard]] size_t remainingCapacity() const
+ {
+ if (length() > capacity()) {
+ return 0;
+ }
+
+ return capacity() - length();
+ }
+
/** \brief The underlying data, guaranteed to have c string representation. */
[[nodiscard]] const utf8* data() const
{
@@ -263,6 +274,11 @@ class String {
return reinterpret_cast<const char*>(data());
}
+ [[nodiscard]] inline StringView asView() const
+ {
+ return StringView(*this);
+ }
+
/** \brief Indicates if the contents of the string form a valid sequence of
* UTF8 code points. */
[[nodiscard]] bool utf8Valid() const;
@@ -274,22 +290,6 @@ class String {
* greater than zero. */
[[nodiscard]] Option<utf8> back();
- /** \brief Returns the remaining capacity for characters excluding the null
- * terminating byte. */
- [[nodiscard]] size_t remainingLength() const
- {
- if (length() > capacity()) {
- return 0;
- }
-
- return capacity() - length();
- }
-
- [[nodiscard]] inline StringView asView() const
- {
- return StringView(*this);
- }
-
FudStatus pushBack(char letter);
FudStatus pushBack(utf8 letter);
@@ -358,6 +358,8 @@ class String {
FudStatus resize(size_t newCapacity);
+ FudStatus grow();
+
/** \brief The allocator used to get storage for characters when the string
* is large. */
uintptr_t m_allocator{reinterpret_cast<uintptr_t>(&globalFudAllocator)};
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp
index 53b2625..a2a0984 100644
--- a/include/fud_vector.hpp
+++ b/include/fud_vector.hpp
@@ -647,8 +647,9 @@ class Vector {
{
// See https://github.com/facebook/folly/blob/main/folly/docs/FBVector.md
size_t additional = m_capacity < 2 ? 1 : m_capacity / 2;
- if (SIZE_MAX - additional * ElementSize < m_capacity * ElementSize) {
- additional = SIZE_MAX - m_capacity * ElementSize / 2;
+ constexpr auto maxSize = std::numeric_limits<size_t>::max();
+ if (maxSize - additional * ElementSize < m_capacity * ElementSize) {
+ additional = maxSize - m_capacity * ElementSize / 2;
}
while (additional > 0) {
auto reserveStatus = reserve(additional + m_capacity);