diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-01-23 15:33:56 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-01-23 15:33:56 -0500 |
| commit | f93dde14496ef784df6b7b3e1de1030a868be985 (patch) | |
| tree | e4f5bcc1852d13e2f2d853a1f6590ccdd93e18a2 /stdlib/text.h | |
| parent | c60ea2079fb230213308904cd0966e5481d2d994 (diff) | |
Overhaul of Text implementation to be more like Cords and have much
better performance for long sequences of repeated concatenation.
Diffstat (limited to 'stdlib/text.h')
| -rw-r--r-- | stdlib/text.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/stdlib/text.h b/stdlib/text.h index 79c094af..64cf86f5 100644 --- a/stdlib/text.h +++ b/stdlib/text.h @@ -13,18 +13,24 @@ #include "types.h" #include "util.h" +#define MAX_TEXT_DEPTH 48 + typedef struct { - Text_t text; - int64_t subtext, sum_of_previous_subtexts; + struct { + Text_t text; + int64_t offset; + } stack[MAX_TEXT_DEPTH]; + int64_t stack_index; } TextIter_t; +#define NEW_TEXT_ITER_STATE(t) (TextIter_t){.stack={{t, 0}}, .stack_index=0} + int printf_text(FILE *stream, const struct printf_info *info, const void *const args[]); int printf_text_size(const struct printf_info *info, size_t n, int argtypes[n], int sizes[n]); #define Text(str) ((Text_t){.length=sizeof(str)-1, .tag=TEXT_ASCII, .ascii="" str}) int Text$print(FILE *stream, Text_t t); -void Text$visualize(Text_t t); Text_t Text$_concat(int n, Text_t items[n]); #define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__}) #define Texts(...) Text$concat(__VA_ARGS__) @@ -69,11 +75,12 @@ void Text$deserialize(FILE *in, void *out, Array_t *, const TypeInfo_t *); MACROLIKE int32_t Text$get_grapheme(Text_t text, int64_t index) { - TextIter_t state = {text, 0, 0}; + TextIter_t state = NEW_TEXT_ITER_STATE(text); return Text$get_grapheme_fast(&state, index); } extern const TypeInfo_t Text$info; +extern Text_t EMPTY_TEXT; #define Text$metamethods ((metamethods_t){ \ .as_text=Text$as_text, \ |
