diff options
| author | raysan5 <raysan5@gmail.com> | 2019-11-24 14:08:27 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2019-11-24 14:08:27 +0100 |
| commit | d5aab98ac9ef0d5387cecc2e5d94383843b49c53 (patch) | |
| tree | b31f3caacae7bad6253871d35ae15a601c3b1c4c | |
| parent | 1f66f0d9a2d9bde9d8aac465739afe33ff174707 (diff) | |
| download | raylib-d5aab98ac9ef0d5387cecc2e5d94383843b49c53.tar.gz raylib-d5aab98ac9ef0d5387cecc2e5d94383843b49c53.zip | |
Review PR #1015
Just simplified code a bit
| -rw-r--r-- | src/text.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -1102,24 +1102,26 @@ 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 +// WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times const char *TextFormat(const char *text, ...) { - #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 }; + #define MAX_TEXTFORMAT_BUFFERS 4 + + // We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations + static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 }; static int index = 0; - char *buffer = cache[index]; - index += 1; - index %= MAX_TEXT_BUFFERS; + + char *currentBuffer = buffers[index]; va_list args; va_start(args, text); - vsprintf(buffer, text, args); + vsprintf(currentBuffer, text, args); va_end(args); + + index += 1; // Move to next buffer for next function call + if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0; - return buffer; - #undef MAX_TEXT_BUFFERS + return currentBuffer; } // Get a piece of a text string |
