1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #105928 from Ivorforce/cowdata-reserve-capacity

Core: Add `reserve` function to `Array`, `Vector`, and `String`
This commit is contained in:
Thaddeus Crews
2025-09-30 11:19:13 -05:00
11 changed files with 441 additions and 201 deletions

View File

@@ -1253,7 +1253,7 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
String buffer = *this;
while (true) {
int idx;
int idx = 0;
int end = findmk(p_splitters, from, &idx);
int spl_len = 1;
if (end < 0) {
@@ -1308,7 +1308,7 @@ Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allo
int len = length();
while (true) {
int idx;
int idx = 0;
int end = findmk(p_splitters, from, &idx);
int spl_len = 1;
if (end < 0) {

View File

@@ -177,10 +177,10 @@ class [[nodiscard]] CharStringT {
public:
_FORCE_INLINE_ T *ptrw() { return _cowdata.ptrw(); }
_FORCE_INLINE_ const T *ptr() const { return _cowdata.ptr(); }
_FORCE_INLINE_ const T *get_data() const { return ptr() ? ptr() : &_null; }
_FORCE_INLINE_ const T *get_data() const { return size() ? ptr() : &_null; }
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
_FORCE_INLINE_ int length() const { return ptr() ? size() - 1 : 0; }
_FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; }
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
_FORCE_INLINE_ operator Span<T>() const { return Span(ptr(), length()); }
@@ -297,10 +297,10 @@ public:
_FORCE_INLINE_ char32_t *ptrw() { return _cowdata.ptrw(); }
_FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
_FORCE_INLINE_ const char32_t *get_data() const { return ptr() ? ptr() : &_null; }
_FORCE_INLINE_ const char32_t *get_data() const { return size() ? ptr() : &_null; }
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
_FORCE_INLINE_ int length() const { return ptr() ? size() - 1 : 0; }
_FORCE_INLINE_ int length() const { return size() ? size() - 1 : 0; }
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
_FORCE_INLINE_ operator Span<char32_t>() const { return Span(ptr(), length()); }
@@ -317,6 +317,11 @@ public:
/// New characters are not initialized, and should be set by the caller.
Error resize_uninitialized(int64_t p_size) { return _cowdata.resize<false>(p_size); }
Error reserve(int64_t p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
return _cowdata.reserve(p_size);
}
_FORCE_INLINE_ const char32_t &operator[](int p_index) const {
if (unlikely(p_index == _cowdata.size())) {
return _null;