diff options
| author | brankoku <48296877+brankoku@users.noreply.github.com> | 2019-11-24 08:01:35 -0500 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2019-11-24 14:01:35 +0100 |
| commit | 1f66f0d9a2d9bde9d8aac465739afe33ff174707 (patch) | |
| tree | f96808ee1879eb2017cc89125c1738943cc100e0 | |
| parent | c1a02e9fcaa9c6e059475aad54c3c9158c4412a5 (diff) | |
| download | raylib-1f66f0d9a2d9bde9d8aac465739afe33ff174707.tar.gz raylib-1f66f0d9a2d9bde9d8aac465739afe33ff174707.zip | |
[text] `TextFormat()` caching (#1015)
| -rw-r--r-- | src/text.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1102,9 +1102,16 @@ unsigned int TextLength(const char *text) } // Formatting of text with variables to 'embed' +// WARNING: the string returned will expire after this function is called MAX_TEXT_BUFFERS times const char *TextFormat(const char *text, ...) { - static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; + #define MAX_TEXT_BUFFERS 8 + // We create an array of buffers so strings don't expire until MAX_TEXT_BUFFERS invocations + static char cache[MAX_TEXT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 }; + static int index = 0; + char *buffer = cache[index]; + index += 1; + index %= MAX_TEXT_BUFFERS; va_list args; va_start(args, text); @@ -1112,6 +1119,7 @@ const char *TextFormat(const char *text, ...) va_end(args); return buffer; + #undef MAX_TEXT_BUFFERS } // Get a piece of a text string |
