Musa-Cpp-Lib-V2/lib/Base/String_Builder.h

27 lines
1.5 KiB
C

// #string_builder
// #limitations This won't be as fast as Jon's String_Builder in jai because we're backing it with an
// Arena, which calls VirtualAlloc, which is much slower than just using stack space to start.
// It also has a max capacity depending on what Arena_Reserve we choose.
// That being said, the implementation is much simpler, and we can keep it around for a bit.
// We can make it a lot faster by always having a string builder available in the thread_context,
// and just fetching that when we need it.
typedef ArenaArray<u8> String_Builder; // struct String_Builder
force_inline String_Builder* new_string_builder (Arena_Reserve new_reserve=Arena_Reserve::Size_64K);
force_inline void append (String_Builder* sb, string s);
void append (String_Builder* sb, ArrayView<string> strings);
// This should probably be called append_but_do_not_increment_count
internal force_inline void append_no_add (String_Builder* sb, string s); // for appending null terminators, does not increment count.
void print_to_builder (String_Builder* sb, string format, ...);
void print_to_builder_internal (String_Builder* sb, string format, va_list args);
string string_view (String_Builder* sb);
internal force_inline void reset_string_builder (String_Builder* sb, bool keep_memory=false);
// #rename copy_string_and_free_builder
force_inline string builder_to_string (String_Builder* sb); // returns copy and frees string_builder
internal force_inline void free_string_builder (String_Builder* sb);