FastLED 3.10.10
Loading...
Searching...
No Matches

◆ grow()

void fl::StringHolder::grow ( size newLength)

Definition at line 84 of file string_holder.cpp.hpp.

84 {
85 if (newLength + 1 <= mCapacity) {
86 // We have enough capacity for newLength + null terminator
87 mLength = newLength;
88 mData[mLength] = '\0';
89 return;
90 }
91
92 // Use fl::realloc for efficient growth without memory move.
93 // Keep the old buffer if the allocation fails — the string simply
94 // does not grow (callers observe the unchanged length).
95 char *grown = nullptr;
96#ifdef FASTLED_TESTING
98#endif
99 {
100 grown = (char*)fl::realloc(mData, newLength + 1);
101 }
102 if (grown == nullptr) {
103 return;
104 }
105 mData = grown;
106 mLength = newLength;
107 mCapacity = newLength + 1;
108 mData[mLength] = '\0'; // Ensure null-termination
109}
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
FASTLED_FORCE_INLINE void * realloc(void *ptr, size_t new_size) FL_NO_EXCEPT
Definition malloc.h:27

References fl::FL_NO_EXCEPT, fl::Singleton< T, N >::instance(), mCapacity, mData, mLength, and fl::realloc().

Referenced by operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: